app支付集成开发者指南

来自    APP支付与登录 | 
作者:王兰玉  |  更新于:2018-09-25 13:32:44     

鉴于很多对接app支付的童鞋经常出现app支付系统繁忙,ali40247,订单信息异常在等等的错误,其实那些错误都是大同小异的,无非就是没权限,密钥不对,参数传值错误,请求信息拼接有问题等等,所以这边写app支付开发指南分享帖,希望能够帮到大家!!!

app支付官方文档地址:https://docs.open.alipay.com/204 

开发前准备工作:

1、签约:https://openclub.alipay.com/read.php?tid=276&fid=72

2、创建应用:https://openclub.alipay.com/read.php?tid=1606&fid=72

3、生成密钥:https://openclub.alipay.com/read.php?tid=1833&fid=69

4、下载服务端sdk:https://docs.open.alipay.com/54/106370/

5、下载客户端demo:https://docs.open.alipay.com/54/104509/

如果大家遇到我上面说的那些错误,第一反应先查签约,确认自己是否签约app支付,地址查看自己的签约,以及生效时间:

https://b.alipay.com/signing/authorizedProductSet.htm?navKey=all&type=myProduct#/myProduct?_k=yb5nbu

或者到https://openhome.alipay.com/platform/appManage.htm#/apps开发者中心查看应用是否是【上线】状态

点击【查看详情】进入

注意:还有一个比较坑的点就是如果你添加app支付功能的时间早于你签约的时间,也是需要先将功能包删除后再重新添加才能正常使用的,否则也会报错

 

沙箱账号查看地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info

如下是沙箱测试用账号密钥,为了防止有些开发会直接拿我的密钥放到正式环境使用,造成安全隐患,我就不把公钥放出来给大家了:

        //沙箱APPID
	public static final  String app_id = "2016101800718925";
	//沙箱私钥
	public static final  String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDfDBUJhaw46ck8MHccIBXPt2USOvCRZ0dQNZZwC0EmZvcnL2+NUyoJMbgcV3U5o6wApajkpibf9UkrtYgI3/GZhOgzfzH0IJYAXmYCEniM+Cl5ipIWhY0W/s+uNRGNdXvNlketNNcVqAvkKZdcHz23N60BXsvjdR+BJ/np2CUmr9OCv0aqqwOO190rOuZvVaFCJD5LDmvDFdXPzrJHcOAyYj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sisLtO0ImbSHrVbRXak4SHXSj+9btQ4yAFwI+6zmzL7bUPt4SUGW0oFXefwa0zpZDDAWZxzxAqNePaPSIgAOUCtECgYEA8zySp0UdBQQOEJuTUJlHgf+FK0jUMREVBi9CQgbK8iF/hDmA34B4z0JCkWEsGojiS3S72ZJBXxrZ8RowJGqLuNZHUAD+eEzjoBhZOIfn2R0Bo2UAZAe6pwERzqOEEVLyBExEV3+qkDwIewx4lghFCQpwhO6SNWj4ppSgXh7XAss=";
	//支付宝公钥
	public static final  String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnVuBUzhfo7kWUN/TS/kHmb4afsAlUVaTR3U5e74V0os1bzlfvh+cpwnwzaEIb36CR1OzeIIzXgARIW/zGAL1/PLG8dFEXQOIGkA0a8YXGVNX9KeWnFCnCQ5gQxrfJ3ryasXzWBxv5bex1VrVsQ2TZ1VdUD+S7dR4SWFHvyck8/xGt3Hz5peUqo/OIlfQpoTBXdqfnJNrTVAMqcQhrIWwgpSVgmUq+UhlZsDaiUvxWWFm9v9nY172jFfzup/DIET//OpIghL6AB2F+ywkCcHdZHiGklnpNoQKQ6XMVKaO/k2nlHU64Y4WGSgJnSG6B798ohZoi3pndrVPAH5+5BKEFQIDAQAB";
	//沙箱网关地址
	public static final  String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

 

注:如果大家用我的沙箱账号测试是成功的,但是用自己的账号密钥测试失败,要么是密钥问题,要么是没签约或者没添加功能包,针对这几点做检查即可。

java版服务端示例

public static void main(String[] args) throws AlipayApiException, UnsupportedEncodingException {
		//获得初始化的AlipayClient
	    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key,AlipayConfig.sign_type);
	    AlipayTradeAppPayRequest alipayRequest=new AlipayTradeAppPayRequest();
	    //设置同步回调地址		
		alipayRequest.setReturnUrl(AlipayConfig.return_url);
		//设置异步回调地址
		alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
		//公共回传参数,用于传值自定义信息,必须encode,不能带单双引号之类的之定义参数,否则会报错
		String passback_params	 = "公用回传参数测试123#34!";
		String passback_params2 =URLEncoder.encode(passback_params,"UTF-8");

		//		alipayRequest.setBizContent("{\"out_trade_no\":\"201809251015343222843\"," 
//				+ "\"total_amount\":\"0.01\"," 
//				+ "\"subject\":\"app支付测试\"," 
//				+ "\"passback_params\":\""+ passback_params2 +"\"," 
//				+ "\"product_code\":\"QUICK_MSECURITY_PAY\"}");
		 AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
		 model.setOutTradeNo("20181012015343222843");
		 model.setTotalAmount("0.01");
		 model.setSubject("app支付subject测试");
		 model.setPassbackParams(passback_params2);
		 model.setProductCode("QUICK_MSECURITY_PAY");
		 alipayRequest.setBizModel(model);
		AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipayRequest);
		
		if(response.isSuccess()){
			System.out.println("调用成功");
		} else {
			System.out.println("调用失败");
		}
		System.out.println(response.getBody());
	}

 

返回信息

alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016101800718925&biz_content=%7B%22out_trade_no%22%3A%22201809251015343222843%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98%E6%B5%8B%E8%AF%95%22%2C%22passback_params%22%3A%22%25E5%2585%25AC%25E7%2594%25A8%25E5%259B%259E%25E4%25BC%25A0%25E5%258F%2582%25E6%2595%25B0%25E6%25B5%258B%25E8%25AF%259512334%25EF%25BC%2581%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&format=JSON&method=alipay.trade.app.pay&notify_url=http%3A%2F%2F106.14.187.178%2Fopendevtools%2Fnotify%2Fdo%2Fa9bed896-0fc0-4b05-ba55-6a2550cacd36&return_url=https%3A%2F%2Fwww.baidu.com%2F&sign=qiOEfMcQoObzuPdZNkMOzavHfJLskTUWJxb08YObj8D0SexDStOw%2BHEwOs7x1hGih8Zs3rsT%2BA3aYVnmwp0FTnTYHx2cTbvz1tkNTzoguOG%2BdNR4b5dsJ%2BvUU4UbHV2KDOxg%2FASUcjcbhqitYraWjBgL02QWgTa%2FpA7dpZnxaOKyksZ1tvp7dR3zYvfDdVnfo3vpXlJxc8QTXsYvZdpODvmKG9odw%2FTsP2fZdt3Up7aiq7Ae8rby%2FNg%2BIMcGJjH%2F5MnUC99%2FU9%2Bjwt%2Biqt7jwU4PVfGimDY6ifIYs3PosGwfwrMTSZkI8AzdcsmwHRcqGJJNzlzegl9jQHw9mBzSAw%3D%3D&sign_type=RSA2&timestamp=2018-09-25+13%3A09%3A52&version=1.0

 

注意:php跟.net 要使用pkcs1的私钥

php代码示例

<?php
require_once 'AopSdk.php';
$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
$aop->appId = '2017121300675523';
$aop->rsaPrivateKey = 'MIIEowIBAAKCAQEAwGTF1qvn5uTvVVao6+hF2JSh36enOF3eJE+xXzCZsbidy3dEy3UBZ28sWNMbEMuPhcqvX7DO9/kP459TJJ4fK3nveJAXp9kvVM0q0dCM71ttpJ1bwN90kweNQc92RxOXo2EVBfGp6X6hu5cXC94OcJwYFIt1wgE9ZZQBFwUo4ZbotJUyw7sKLHRk/fs6WliM18qUtF3IeSUHP1ro7QuZKd10PqCiQXXSA6oTYzAFBJmrMwrkl9ZHOGvK8fQvRRnEOwn2Chy1/p9GnKvt4awTNq6p3g1gU/kZqF7HieJbtCurKIhdFOqH2XRztfBdGf81ldmb/bbDo8/7WhWqFhQoFQIDAQABAoIBAQCwSGWh4hd1T5Uf+2yB42yEGwQLGuG0WwXc/YxG7RAWcFNdB+ZoCciEjq/yn1OwWuQhsepo4mdxfKsbZHPZHGzw+CP8swKJ0A13RRoT72QDOSHIcEqO+fAlfAjpIP999qy9jYmmzZxjDp2AddsvC4LtmYjS4km+vkYUWb1560dfEr41H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gkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnVuBUzhfo7kWUN/TS/kHmb4afsAlUVaTR3U5e74V0os1bzlfvh+cpwnwzaEIb36CR1OzeIIzXgARIW/zGAL1/PLG8dFEXQOIGkA0a8YXGVNX9KeWnFCnCQ5gQxrfJ3ryasXzWBxv5bex1VrVsQ2TZ1VdUD+S7dR4SWFHvyck8/xGt3Hz5peUqo/OIlfQpoTBXdqfnJNrTVAMqcQhrIWwgpSVgmUq+UhlZsDaiUvxWWFm9v9nY172jFfzup/DIET//OpIghL6AB2F+ywkCcHdZHiGklnpNoQKQ6XMVKaO/k2nlHU64Y4WGSgJnSG6B798ohZoi3pndrVPAH5+5BKEFQIDAQAB';
$aop->apiVersion = '1.0';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->signType = 'RSA2';
//生成随机订单号
$date=date("YmdHis");
$arr=range(1000,9999);
shuffle($arr);
$request = new AlipayTradeAppPayRequest();
//异步地址传值方式
$request->setNotifyUrl("https://www.alipay.com");
$request->setBizContent("{\"out_trade_no\":\"".$date.$arr[0]."\",\"total_amount\":0.01,\"product_code\":\"QUICK_MSECURITY_PAY\",\"subject\":\"app测试\"}");
$result = $aop->sdkExecute($request);
print_r(htmlspecialchars($result));
?>

 

返回结果

alipay_sdk=alipay-sdk-php-20161101&app_id=2017121300675523&biz_content=%7B%22out_trade_no%22%3A%22201809250359474566%22%2C%22total_amount%22%3A0.01%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22app%E6%B5%8B%E8%AF%95%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay&notify_url=https%3A%2F%2Fwww.alipay.com&sign_type=RSA2&timestamp=2018-09-25+03%3A59%3A47&version=1.0&sign=ueXycfafCqB2Uc31pyAjiRF4rDW5nn8MCT8Hy0lB8jukbgLyhn76hVKuw7mOgqGQwxVdYWq7Rm2A%2FpXBPwjWBcifuowtoiyB2hhw2FHR6yje8xKNNe3jGfVPrMxyze0HmOD3BQwzz53U4VcpQACRHbAZU8ZOT3U8MzJnJqMCsdD8IGZU1b8meig1gn6DANvMfmKuubUNod5DFMJlEpHZENMzSw5F546TW%2Bz6VhyxC6Hzp0%2FFd%2BF8zHK9THbyK6sR4EJQfvm7hmdOR%2FRKaS3RxHbBZ%2BZha%2FFjwA0hFYXTI6D7xB5cGiVtQCfrDmPZaQvwY7jdNDuav1dHj1is5nsjWw%3D%3D

 

.net示例

公共参数:

  public class Config
    {
        //应用appId沙箱
        public static string appId = "2016101800718925";

        //支付宝网关
        public static string serverUrl = "https://openapi.alipaydev.com/gateway.do";

        //沙箱支付宝公钥
        public static string alipay_public_key = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnVuBUzhfo7kWUN/TS/kHmb4afsAlUVaTR3U5e74V0os1bzlfvh+cpwnwzaEIb36CR1OzeIIzXgARIW/zGAL1/PLG8dFEXQOIGkA0a8YXGVNX9KeWnFCnCQ5gQxrfJ3ryasXzWBxv5bex1VrVsQ2TZ1VdUD+S7dR4SWFHvyck8/xGt3Hz5peUqo/OIlfQpoTBXdqfnJNrTVAMqcQhrIWwgpSVgmUq+UhlZsDaiUvxWWFm9v9nY172jFfzup/DIET//OpIghL6AB2F+ywkCcHdZHiGklnpNoQKQ6XMVKaO/k2nlHU64Y4WGSgJnSG6B798ohZoi3pndrVPAH5+5BKEFQIDAQAB";

        //开发者原始私钥,千万不要用pkcs8格式的 沙箱
        public static string merchant_private_key = @"MIIEowIBAAKCAQEA3wwVCYWsOOnJPDB3HCAVz7dlEjrwkWdHUDWWcAtBJmb3Jy9vjVMqCTG4HFd1OaOsAKWo5KYm3/VJK7WICN/xmYToM38x9CCWAF5mAhJ4jPgpeYqSFoWNFv7PrjURjXV7zZZHrTTXFagL5CmXXB89tzetAV7L43UfgSf56dglJq/Tgr9GqqsDjtfdKzrmb1WhQiQ+Sw5rwxXVz86yR3DgMmI29oYSSFreZ+KP29yzGHrsX8FrkOFZRsfrNMGS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h61W0V2pOEh10o/vW7UOMgBcCPus5sy+21D7eElBltKBV3n8GtM6WQwwFmcc8QKjXj2j0iIADlArRAoGBAPM8kqdFHQUEDhCbk1CZR4H/hStI1DERFQYvQkIGyvIhf4Q5gN+AeM9CQpFhLBqI4kt0u9mSQV8a2fEaMCRqi7jWR1AA/nhM46AYWTiH59kdAaNlAGQHuqcBEc6jhBFS8gRMRFd/qpA8CHsMeJYIRQkKcITukjVo+KaUoF4e1wLL";

        public static string format = "json";


   
        //编码,无需修改
        public static string charset = "utf-8";

        //签名类型,支持RSA2(推荐!)、RSA
        public static string sign_type = "RSA2";

        //版本号,无需修改
        public static string version = "1.0";


        /// <summary>
        /// 私钥文件类型转换成纯文本类型
        /// </summary>
        /// <returns>过滤后的字符串类型私钥</returns>
        public static string getMerchantPriveteKeyStr()
        {
            StreamReader sr = new StreamReader(merchant_private_key);
            string pubkey = sr.ReadToEnd();
            sr.Close();
            if (pubkey != null)
            {
                pubkey = pubkey.Replace("-----BEGIN PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("-----END PUBLIC KEY-----", "");
                pubkey = pubkey.Replace("\r", "");
                pubkey = pubkey.Replace("\n", "");
            }
            return pubkey;
        }

    }

 

请求示例

  static void Main(string[] args)
        {
             IAopClient client = new DefaultAopClient("https://openapi.alipaydev.com/gateway.do", Com.Alipay.Config.appId, Com.Alipay.Config.merchant_private_key, "json", "1.0", "RSA2", Com.Alipay.Config.alipay_public_key, "GBK", false);
             AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();//创建API对应的request
             AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
             model.OutTradeNo = "201809251315181234561223434123";
             model.Subject = "手机网站支付测试";
             model.TotalAmount = "0.01";
             model.ProductCode = "QUICK_MSECURITY_PAY";
             alipayRequest.SetBizModel(model);
             AlipayTradeAppPayResponse response = client.SdkExecute(alipayRequest);
             Console.WriteLine("接口调用返回信息:" + response.Body);
        }

 

.net返回结果

接口调用返回信息:app_id=2016101800718925&biz_content=%7b%22out_trade_no%22%3a%22201809251315181234561223434123%22%2c%22product_code%22%3a%22QUICK_MSECURITY_PAY%22%2c%22subject%22%3a%22%ca%d6%bb%fa%cd%f8%d5%be%d6%a7%b8%b6%b2%e2%ca%d4%22%2c%22total_amount%22%3a%220.01%22%7d&charset=GBK&format=json&method=alipay.trade.app.pay&sign_type=RSA2&timestamp=2018-09-25+12%3a06%3a52&version=1.0&sign=HIatgoFqis%2bgwCPw%2bnDGQhbBR3i7X4P%2fnagTXO6DkLVLi7kPjx233skwjtpwnFzmSHIp84%2foaBpUHkPXMAkX%2b7rBJdYxW5FLqNXz9DYZh5NBtzmoNfpD%2baPUaIO%2fKylESh3r0Twgz4BQcmdJ6HkS4Erq5blTFHNK8OUB9ISI9absu30fS5teYBkkBkM2QDaMIpIxAzjvIBPZzUZU7%2fgXIq%2f3A9B5f7E70QH1hycktjjk8RgC%2fsTjMWx%2f8q2WN5T0fj9053WM%2b34CFhzXK9kNkI2Hf2Sd6e%2fBlToS%2bYt1%2bByvtiYifrWIxc1ldBbWtH5NqcXpgYzwk1JHjieSeTqn%2fw%3d%3d

 

如果不是使用sdk签名方式,使用的是自己的签名方法,参数排序请严格按照我们文档的排查方式,不要随意排序拼接,详情请参考文档:https://docs.open.alipay.com/204/105465/

 

客户端集成

生成请求示例之后,我们再将示例中的信息传值到客户端,无需做任何处理,直接传值

//将服务端生成的请求信息不做任何处理直接传入客户端,调用收银台
final String orderInfo ="alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2014100900013222&biz_content=%7B%22out_trade_no%22%3A%2220180823101534222843%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98%E6%B5%8B%E8%AF%95%22%2C%22passback_params%22%3A%22%25E5%2585%25AC%25E7%2594%25A8%25E5%259B%259E%25E4%25BC%25A0%25E5%258F%2582%25E6%2595%25B0%25E6%25B5%258B%25E8%25AF%2595123%252334%25EF%25BC%2581%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&format=JSON&method=alipay.trade.app.pay&notify_url=http%3A%2F%2F106.14.187.178%2Fopendevtools%2Fnotify%2Fdo%2Fa9bed896-0fc0-4b05-ba55-6a2550cacd36&return_url=https%3A%2F%2Fwww.baidu.com%2F&sign=RyGvj%2FyEFCBDNbFjMKJGToD13kSO12LzEqd%2FXTKiMADlILQwvWM7ec4gIT6tf6EcnTry%2Fe325EHfFIjUjQSqpOmqftssyZF0jQpMX8Nd7Km%2F%2FE4H9BEP6QgdPE7lgPItE5mwFYmkUVKJmO6Bf1Zodn3sQcEQp%2FanTmK0tivX9ZpFup%2BLJKexIOgrGb3baAfWJdp1KX4CTPB3JlUHG2FuAFdblsjjZvzI8mv6A6PBjt72C%2B2vTAAMFhakAvY7j6ql23dVMxlKCA19ar11cBrEY6hH5uxhVhAb%2BcCzBm07RqiqXwMFBXVnUpTcE%2FIcG1Gx4zPE9WW3BxmCCI2RavZ0yQ%3D%3D&sign_type=RSA2&timestamp=2018-09-25+11%3A48%3A38&version=1.0";		
	
		Runnable payRunnable = new Runnable() {

			@Override
			public void run() {
				PayTask alipay = new PayTask(PayDemoActivity.this);
				Map<String, String> result = alipay.payV2(orderInfo, true);
				Log.e("msp", result.toString());
				
				Message msg = new Message();
				msg.what = SDK_PAY_FLAG;
				msg.obj = result;
				mHandler.sendMessage(msg);
			}
		};

		Thread payThread = new Thread(payRunnable);
		payThread.start();

 

沙箱集成注意事项

沙箱环境测试只支持安卓版,使用官方sdk,需要在支付接口前调用如下方法;

详情请参考文档:https://docs.open.alipay.com/204/106450/

EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);

 

测试效果

登录沙箱账号点击【下一步】,进入账单详情,点击【确认付款】,进入输入密码页面

注意:未输入密码之前,支付宝订单还是为创建状态,只有输入密码之后,才会生成支付宝订单,所以这个时候用查询接口查询会报错“订单不存在”

 

如有疑问,欢迎大家留言提问或者吐槽,谢谢大家!!!!

图小助 | 2018-10-28 11:40:56
请教下,java服务器端返回的alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016101800718925&biz_content=%7B%22out_trade_no%22%3A%22201809251015343222843%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98%E6%B5%8B%E8%AF%95%22%2C%22passback_params%22%3A%22%25E5%2585%25AC%25E7%2594%25A8%25E5%259B%259E%25E4%25BC%25A0%25E5%258F%2582%25E6%2595%25B0%25E6%25B5%258B%25E8%25AF%259512334%25EF%25BC%2581%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&format=JSON&method=alipay.trade.app.pay&notify_url=http%3A%2F%2F106.14.187.178%2Fopendevtools%2Fnotify%2Fdo%2Fa9bed896-0fc0-4b05-ba55-6a2550cacd36&return_url=https%3A%2F%2Fwww.baidu.com%2F&sign=qiOEfMcQoObzuPdZNkMOzavHfJLskTUWJxb08YObj8D0SexDStOw%2BHEwOs7x1hGih8Zs3rsT%2BA3aYVnmwp0FTnTYHx2cTbvz1tkNTzoguOG%2BdNR4b5dsJ%2BvUU4UbHV2KDOxg%2FASUcjcbhqitYraWjBgL02QWgTa%2FpA7dpZnxaOKyksZ1tvp7dR3zYvfDdVnfo3vpXlJxc8QTXsYvZdpODvmKG9odw%2FTsP2fZdt3Up7aiq7Ae8rby%2FNg%2BIMcGJjH%2F5MnUC99%2FU9%2Bjwt%2Biqt7jwU4PVfGimDY6ifIYs3PosGwfwrMTSZkI8AzdcsmwHRcqGJJNzlzegl9jQHw9mBzSAw%3D%3D&sign_type=RSA2&timestamp=2018-09-25+13%3A09%3A52&version=1.0 这个信息到底是错还是对? 另外正常来说不是应该会生成一个预支付的Id么?
天籁 | 2018-10-29 09:54:51
图小助:请教下,java服务器端返回的alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016101800718925&biz_content=%7B%22out_trade_no%22%3A%...回到原帖
APP支付的接口服务端返回的就是这个请求字符串 客户端拿到这个请求字符串来唤起支付的
Dokuro | 2018-10-29 18:08:42
你好 请问 服务端返回这个请求字符串app_id=2016070601586270&biz_content=%7b%22body%22%3a%22%7b%5c%22Type%5c%22%3a%5c%221%5c%22%7d%22%2c%22out_trade_no%22%3a%22183218875121810260003_1540807593%22%2c%22product_code%22%3a%22QUICK_MSECURITY_PAY%22%2c%22subject%22%3a%22aibici%22%2c%22timeout_express%22%3a%2230m%22%2c%22total_amount%22%3a%2217.00%22%7d&charset=utf-8&format=json&method=alipay.trade.app.pay&notify_url=http%3a%2f%2fapitest.aibici.com%2fApi%2fCallBack%2fAliNotify&sign_type=RSA&timestamp=2018-10-29+18%3a06%3a33&version=1.0&sign=vTPnRfsXjxG7RUBmgYjTWeOXIbJJBXMaY6Ibhe4fUtVy4HI8gARBIohH%2bmM%2fpC8YFu8ybwP3lBIKXMrihyyJ7kZnaPU53dHSk3KV0yMgVeuHJ8Yvj3BGtnd4s%2bKhm73cRJ1wm46KnsCbhcoQsbyp7fokQWNAWCpbk2OVSxRtUfo%3d 客户端进行调用时,跳转支付宝没任何反应,求教啥问题
王兰玉 | 2018-10-30 09:22:06
Dokuro:你好 请问 服务端返回这个请求字符串app_id=2016070601586270&biz_content=%7b%22body%22%3a%22%7b%5c%22Type%5c%22%3a%5c%221%5c%22%7d%22%2c%22...回到原帖

你好,这边使用你提供的请求参数是可以调用收银台的,建议参考我们客户端demo测试,应该是客户端集成有问题导致无法吊起收银台

colabread | 2018-10-30 10:27:51
求客户端 ajax唤起支付宝的代码!!!! 后端已经生产了一串“alipay-sdk-java-3.3.49.ALL&app_id ...” 前段没办法唤起客户端 备注:采用的是H5方式
王兰玉 | 2018-10-30 10:48:10
colabread:求客户端 ajax唤起支付宝的代码!!!! 后端已经生产了一串“alipay-sdk-java-3.3.49.ALL&app_id ...” 前段没办法唤起客户端 备注:采用的是H5方式回到原帖
你好,app支付是不支持ajax唤起h5的,你这边想实现h5支付,请使用手机网站支付,如果你这边想要使用APP支付只能使用我们文档中的方式进行唤起收银台
图小助 | 2018-10-30 23:55:05
图小助:请教下,java服务器端返回的alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016101800718925&biz_content=%7B%22out_trade_no%22%3A%...回到原帖
另外想问下支付宝的预支付订单与最后的支付订单是一个号?
天籁 | 2018-10-31 09:31:20
图小助:另外想问下支付宝的预支付订单与最后的支付订单是一个号?回到原帖
你说的是支付宝的扫码支付接口吗?你这边调用接口的时候需要你自己传入你自己设置的订单号 也就是out_trade_no参数 这个是你自己定义的 这个订单号发到支付宝后支付宝会依据你的这个订单号再生成一个支付宝订单号trade_no 一共两个订单号 这两个订单号是对应的关系
杭州育泰教育 | 2018-10-31 10:24:29
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016092000551400&biz_content=%7B%22out_trade_no%22%3A%2220181012015343222843%22%2C%22passback_params%22%3A%22%25E5%2585%25AC%25E7%2594%25A8%25E5%259B%259E%25E4%25BC%25A0%25E5%258F%2582%25E6%2595%25B0%25E6%25B5%258B%25E8%25AF%2595123%252334%25EF%25BC%2581%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98subject%E6%B5%8B%E8%AF%95%22%2C%22total_amount%22%3A%220.01%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=www.baidu.com&return_url=https%3A%2F%2Fwww.baidu.com%2F&sign=gv8ffhLkcttlPkhA0%2B7YWu0yLQvtxSWfkBCAew%2FhTt7re4687g%2Fq48axtkQSFCgsAf6r1BE24LjSiEbbRm3Zajtxv6XumbC3a3PtARQxYMmbYmEkAOFS6LvWh%2By9HQ1Obeu1Wm%2F2r1tdMLedU9WFbJx68yHFey9ZT3%2BQtgeXBiQ%3D&sign_type=RSA2&timestamp=2018-10-31+10%3A18%3A20&version=1.0 这是我的返回信息 有什么问题吗? 我这报未知错误
天籁 | 2018-10-31 10:28:53
杭州育泰教育:alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016092000551400&biz_content=%7B%22out_trade_no%22%3A%222018101201534...回到原帖
passback_params是非必传参数 建议取消 还有return_url在APP支付的接口中是没有这个参数的不能传入 也是需要取消的 你修改一下在测试一下
杭州育泰教育 | 2018-10-31 10:37:34
天籁:passback_params是非必传参数 建议取消 还有return_url在APP支付的接口中是没有这个参数的不能传入 也是需要取消的 你修改一下在测试一下回到原帖
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016092000551400&biz_content=%7B%22out_trade_no%22%3A%2220181012015343222843%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98subject%E6%B5%8B%E8%AF%95%22%2C%22total_amount%22%3A%220.01%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Fwww.bcty365.com%2Fcontent-146-6172-1.html&sign=EfmF83RFe8Mp18KZqx1n7oUDfnuotDUzKCErygqHKztKVQnHQFf1UGPD51T1EMqQftULV5WDnDIRfD5Eb0xr5jr3nJQsRXg%2FB3kFYkteKuSnFb2yhZc3uac1YApDtVvDkbuffpej7bPQnakFnH6tJwX4dDlrCUuhMZH9r1h62jI%3D&sign_type=RSA2&timestamp=2018-10-31+10%3A35%3A02&version=1.0 还是未知错误, 未知错误是什么原因啊
天籁 | 2018-10-31 10:47:48
杭州育泰教育:alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016092000551400&biz_content=%7B%22out_trade_no%22%3A%222018101201534...回到原帖
out_trade_no外部订单号修改一下 每一次请求都不能相同 保证唯一 如果还是不行 建议参考这个帖子验证一下你的app_id=2016092000551400的沙箱应用秘钥是否匹配:https://openclub.alipay.com/read.php?tid=1486&fid=69
杭州育泰教育 | 2018-10-31 10:55:25
天籁:out_trade_no外部订单号修改一下 每一次请求都不能相同 保证唯一 如果还是不行 建议参考这个帖子验证一下你的app_id=2016092000551400的沙箱应用秘钥是否匹配:https://openclub.alipay....回到原帖
这个外部订单号是我写死的 现在我用的沙箱环境测试的 我改一下试一下 沙箱的秘钥刚刚看了 对着呢
杭州育泰教育 | 2018-10-31 10:58:36
天籁:out_trade_no外部订单号修改一下 每一次请求都不能相同 保证唯一 如果还是不行 建议参考这个帖子验证一下你的app_id=2016092000551400的沙箱应用秘钥是否匹配:https://openclub.alipay....回到原帖
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016092000551400&biz_content=%7B%22out_trade_no%22%3A%2220181012015343245982%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22app%E6%94%AF%E4%BB%98subject%E6%B5%8B%E8%AF%95%22%2C%22total_amount%22%3A%220.01%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Fwww.bcty365.com%2Fcontent-146-6172-1.html&sign=bTZCFRo7RPnRm12TIrrkGY2A2daBedrO4PxQMBdCG8edcqgD2uw9O3aD6%2Ft%2BEz2%2B7BVJx%2BUg9p%2B9tXE9dqOYbTb4CLn282BSVuBKW9hdQI1SRf4rf%2Fm5AJ8iiaM2dyQtT%2FFwpQBHDZYSL5pwbvfcaMXfsu9bnok7U9EfMfxlKZNaorIOG8wxuSQ8PawR%2BYWEvQoQj%2BkemajbfbT7gd%2FeF08wTQahmky4SPX873fvS2tz3UrTAlPWAyf%2BuQALH7iR7iR%2FMClKWzsmkxqisSF29n%2B3W41b3j%2BZUn3A0vg7QrYuIXpyX4zhZw6%2FpyIr4wMGHkmTZXoPuDSY4CQIaSwVZQ%3D%3D&sign_type=RSA2&timestamp=2018-10-31+10%3A53%3A51&version=1.0 返回码是62009 未知错误
我的回复

返回顶部