开发者社区> 问答> 正文

现金红包alipay.fund.trans.app.pay调用问题

  • 沙箱环境和真实环境问题一致
  • .net和java版本SDK问题现象
  • 以下是基于JAVA沙箱环境代码
  • 请求时候均为302条转导致catch,并没有实际返回.
  • 调用其他API都可以返回,比如没权限之类的最起码不是302重定向.跟踪步骤发现302跳转无法正常返回内容
  • sdk版本试过很多,证书更换过很多次,复现均一致[接口]没有返回信息而是302定向,.net版本直接302中断catch.java为五返回信息catch(实则也是302)
  • 返回HTTP头里还有个奇怪的 ULR
mobilecashier.d6243.alipaydev.com:12200?alipay_exterface_invoke_assign_target=invoke_e49649dc7dbc7e6a84e4de998cbfbbb5&alipay_exterface_invoke_assign_sign=_emww78n2_cg_l_n_em_o_x3_t_kija_ci_cap_p_t2h_vb4_synj0_g_q_v_j_veuvy%2Bn_upg_a%3D%3D

引用外部库: 1. JAVA SE 12.0.1 2. alipay-sdk-java-4.5.0.ALL-sources.jar 3. alipay-sdk-java-4.5.0.ALL.jar 4. bcprov-jdk15on-1.62-sources.jar 5. bcprov-jdk15on-1.62.jar 6. commons-logging-1.1.1-sources.jar 7. commons-logging-1.1.1.jar - 代码如下:

String gateway="https://openapi.alipaydev.com/gateway.do";
				String app_id="2016092500594774";
				String app_privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7YIOCmA20pXEm9dleTOoZfgadEfoetZLhzeOsZgVfjRsmmxaOeRAaW0RTxh/87RG7O7Rz3+TF2/J/Sjf8boBD/dfKsaBbHI6FzdKDMSHoRmeUEhZZUESa6ICice/hqhqAUx1l4Xc3VvNsSUJkvjtW5MfR/zPh4d+PJOvB8nW3mgKdq5OHLSWdIZzXF5oAt1sRvWHb/M6zTUPP2D4fkNTXfrRL8H1XUDTZyZfUN5GJsPdhFGlKvIYu7Qu3WCYUpEq3bB4vnuYD1XrsUqLw7COEE8Xx4yo/rVHBdE/QyPD64xRrspWmwWpqwpBQonM6CSJTPYA0WTjacRlMDD1LaP/RAgMB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OZlzpYiBwl6nCPazs4o0sl0swySyfibT5MX3I8g12m1uLqvXSbR3PhBWp1gIDeCrkir0QsUScz0zvXJLDpoIWFYWfargo3DW2jzndCtlFQ71R4FvCLsq4TnCqrCJc0mju1K+VYvp/2kVqPnRe/IR+5rd";
				String app_cert_path="appCertPublicKey_2016092500594774.crt";
				String alipay_cert_path="alipayCertPublicKey_RSA2.crt";
				String alipay_root_cert_path="alipayRootCert.crt";
				
				CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
				certAlipayRequest.setServerUrl(gateway);
				certAlipayRequest.setAppId(app_id);
				certAlipayRequest.setPrivateKey(app_privateKey);
				certAlipayRequest.setFormat("json");
				certAlipayRequest.setCharset("UTF-8");
				certAlipayRequest.setSignType("RSA2");
				certAlipayRequest.setCertPath(app_cert_path);
				certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
				certAlipayRequest.setRootCertPath(alipay_root_cert_path);
				DefaultAlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
		 
		        
				AlipayFundTransAppPayRequest request = new AlipayFundTransAppPayRequest();
				request.setBizContent("{" +
				"\"out_biz_no\":\""+getRandomFileName()+"\"," +
				"\"trans_amount\":\"8.88\"," +
				"\"product_code\":\"STD_RED_PACKET\"," +
				"\"biz_scene\":\"PERSONAL_PAY\"," +
				"\"remark\":\"拼手气红包\"," +
				"\"order_title\":\"钉钉拼手气红包\"," +
				"\"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\",\\\"payer_binded_alipay_uid:\\\"2088102177237745\\\"}\"" +
				"}");
				AlipayFundTransAppPayResponse response = alipayClient.certificateExecute(request);
  • 参数如下:
{
    "out_biz_no":"7386020191017",
    "trans_amount":"8.88",
    "product_code":"STD_RED_PACKET",
    "biz_scene":"PERSONAL_PAY",
    "remark":"拼手气红包",
    "order_title":"钉钉拼手气红包",
    "business_params":"{"sub_biz_scene":"REDPACKET","payer_binded_alipay_uid:"2088102177237745"}"
}
  • Log如下
10月 17, 2019 11:55:46 上午 com.alipay.api.internal.util.AlipayLogger _logCommError
严重: 2019-10-17 11:55:46^_^alipay.fund.trans.app.pay^_^null^_^127.0.0.1^_^Mac OS X^_^alipay-sdk-java-4.5.0.ALL^_^https://openapi.alipaydev.com/gateway.do?app_cert_sn=f0909e13848a0a628360503b29ce3725&charset=UTF-8&alipay_root_cert_sn=6bc29aa3b4d406c43483ffea81e08d22&method=alipay.fund.trans.app.pay&sign=Nqt%2F9lQb9bLioZ3XgQ9fWvygDPPBrnYeEFjN9MZSJ9n78Na2QfranZxBlOvE01HPIitRkrx9IjUebRgsADKn6TsJWH6Yd32i%2BOVEdUtzBfLEVhTfS4AlWDKrpVwrDvyLVg3i0HfwVd%2BB6uploLNwV0P5yh3GtkLGDCF8fu6wADqIbzYG%2BMS2imZ03cDPtK6mZsNPRDt6NwyEhNdBd9cNM87o9h1lqUoeGBNn3%2FpiwAKNNFI24PvRW72FUStFz%2BYPQOVo8OrwMdSwbo2KFmvg4nMeUha7UOgAmkWgHBajK0x0WvvLekb1BXV7xbSXFs2ED%2Bx2%2FtJUEQ3oMR3NnYrimA%3D%3D&version=1.0&app_id=2016092500594774&sign_type=RSA2&timestamp=2019-10-17+11%3A55%3A46&alipay_sdk=alipay-sdk-java-4.5.0.ALL&format=json^_^HTTP_ERROR_302^_^unknown protocol: mobilecashier.d6243.alipaydev.com
10月 17, 2019 11:55:46 上午 com.alipay.api.internal.util.AlipayLogger logBizError
严重: com.alipay.api.AlipayApiException: java.net.MalformedURLException: unknown protocol: mobilecashier.d6243.alipaydev.com
com.alipay.api.AlipayApiException: com.alipay.api.AlipayApiException: java.net.MalformedURLException: unknown protocol: mobilecashier.d6243.alipaydev.com
	at com.alipay.api.AbstractAlipayClient._certificateExecute(AbstractAlipayClient.java:275)
	at com.alipay.api.AbstractAlipayClient.certificateExecute(AbstractAlipayClient.java:229)
	at com.alipay.api.AbstractAlipayClient.certificateExecute(AbstractAlipayClient.java:223)
	at com.alipay.api.AbstractAlipayClient.certificateExecute(AbstractAlipayClient.java:217)
	at qrcode.alipay.trade.app.pay.qrcode_app_pay.main(qrcode_app_pay.java:59)
Caused by: com.alipay.api.AlipayApiException: java.net.MalformedURLException: unknown protocol: mobilecashier.d6243.alipaydev.com
	at com.alipay.api.AbstractAlipayClient.doPost(AbstractAlipayClient.java:1009)
	at com.alipay.api.AbstractAlipayClient._certificateExecute(AbstractAlipayClient.java:237)
	... 4 more
Caused by: java.net.MalformedURLException: unknown protocol: mobilecashier.d6243.alipaydev.com
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1963)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1958)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:551)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1957)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1525)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246)
	at com.alipay.api.internal.util.WebUtils.getResponseAsString(WebUtils.java:436)
	at com.alipay.api.internal.util.WebUtils.doPost(WebUtils.java:155)
	at com.alipay.api.internal.util.WebUtils.doPost(WebUtils.java:116)
	at com.alipay.api.AbstractAlipayClient.doPost(AbstractAlipayClient.java:1005)
	... 5 more
Caused by: java.net.MalformedURLException: unknown protocol: mobilecashier.d6243.alipaydev.com
	at java.base/java.net.URL.<init>(URL.java:657)
	at java.base/java.net.URL.<init>(URL.java:546)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2659)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1843)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3084)
	at java.base/java.net.URLConnection.getContentType(URLConnection.java:519)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getContentType(HttpsURLConnectionImpl.java:398)
	at com.alipay.api.internal.util.WebUtils.getResponseAsString(WebUtils.java:433)
	... 8 more
  • 跟进调试如下(堆栈):
WebUtils.getResponseAsString(HttpURLConnection) line: 436	
WebUtils.doPost(String, String, byte[], int, int, String, int) line: 155	
WebUtils.doPost(String, Map<String,String>, String, int, int, String, int) line: 116	
DefaultAlipayClient(AbstractAlipayClient).doPost(AlipayRequest<T>, String, String, String) line: 1005	
DefaultAlipayClient(AbstractAlipayClient)._certificateExecute(AlipayRequest<T>, String, String) line: 237	
DefaultAlipayClient(AbstractAlipayClient).certificateExecute(AlipayRequest<T>, String, String) line: 229	
DefaultAlipayClient(AbstractAlipayClient).certificateExecute(AlipayRequest<T>, String) line: 223	
DefaultAlipayClient(AbstractAlipayClient).certificateExecute(AlipayRequest<T>) line: 217	
qrcode_app_pay.main(String[]) line: 60	
  • 跟进调试如下(异常行):
  • 详情看代码备注
//SDK文件WebUtils.class
   protected static String getResponseAsString(HttpURLConnection conn) throws IOException {
        String charset = getResponseCharset(conn.getContentType());
        InputStream es = conn.getErrorStream();
        if (es == null) {
        //conn.getInputStream() 出现异常
        //异常信息 unknown protocol: mobilecashier.d6243.alipaydev.com
            return getStreamAsString(conn.getInputStream(), charset);
        } else {
            String msg = getStreamAsString(es, charset);
            if (StringUtils.isEmpty(msg)) {
                throw new IOException(conn.getResponseCode() + ":" + conn.getResponseMessage());
            } else {
                throw new IOException(msg);
            }
        }
    }
  • 中断变量:
#conn->delegate->respones
sun.net.www.MessageHeader@120f102b14 pairs: {null: HTTP/1.1 302 Found}{Server: Tengine/2.1.0}{Date: Thu, 17 Oct 2019 04:10:10 GMT}{Content-Type: application/octet-stream}{Connection: keep-alive}{Set-Cookie: zone=GZ00B; Domain=.alipaydev.com; Path=/}{location: mobilecashier.d6243.alipaydev.com:12200?alipay_exterface_invoke_assign_target=invoke_1845fdc8e294331080cb3ae27698daa3&alipay_exterface_invoke_assign_sign=_s_ln7d2_t_a_k_a_zfnx02f62_fev%2B_x32_qpm8ukh5_qo_xv%2F_wy2iy_hr2_i_xp4_qz_a%3D%3D}{connection: keep-alive}{content-length: 0}{set-cookie: JSESSIONID=8E05DCCF71F78EF8E8D1C3268E3ACAC4; Path=/; HttpOnly}{set-cookie: ALIPAYJSESSIONID=GZ00wcmu50ldarQsnJi2qwg2teuSJdsuperapiGZ00; Domain=.alipaydev.com; Path=/}{set-cookie: ctoken=xobwl7Tev1kFc61-; Domain=.alipaydev.com; Path=/}{Set-Cookie: spanner=r7Gde3HSucXTedbI2QGl1ewBN9Uv8Bn2Xt2T4qEYgj0=;path=/;secure;}{Via: gateway-2-1-2.daily.alipay.net[302],11.166.43.162:80[302]}

展开
收起
米子丁 2019-10-17 11:30:05 13149 0
4 条回答
写回答
取消 提交回答
  • 楼主这个问题有解决吗??我也遇到了。。。。。

    2020-04-27 16:51:59
    赞同 展开评论 打赏
  • 我也碰到这个问题 返回的是html 并不是我请求的JSON 我也是服了

    2019-11-02 01:52:06
    赞同 展开评论 打赏
  • 支付宝小程序开发者运营专家

    遇技术问题,请加支付宝官方技术钉钉群:23362130,有专门的技术支持回答。

    2019-10-26 10:39:01
    赞同 展开评论 打赏
  • 使用场景错误,服务端只是加签请求参数,实际的请求是需要支付宝App的SDK发起请求。 image.png

    2019-10-18 10:53:17
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
问答排行榜
最热
最新

相关电子书

更多
女性移动App安全攻防战 立即下载
汇聚云计算的生态核能——云市场,云上APP Store 立即下载
千万级用户直播App——服务端架构设计和思考 立即下载

相关实验场景

更多