云闪付聚合支付踩坑

一、获取授权code
1、云闪付code

a.首先提供域名向银联申请此安全域名(例如:https://yyy.xxxxxx.com)
b.之后在前端调用云闪付获取授权码

window.location.href='https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl='
            + encodeURIComponent('https://域名/项目路径/index.html');//这里是code回调的页面
2、支付宝code

a.在支付宝开放平台申请网页&移动端应用
b.首先在应用信息里设置公钥私钥 以及授权回调地址
切记支付宝授权回调地址和前端写的要保持一直例如:https:xxx.xxx.com/xxx/index.html
c.之后在概览=》添加功能=》添加获取会员信息选项
d.在前端进行调用获取支付宝授权码

var redirectUrl = encodeURIComponent('https://域名/项目路径/index.html')//支付宝code回调地址
window.location.href = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=appid&redirect_uri='+redirectUrl+'&scope=auth_base&state=init';
e.获取userId
3、微信code

a.需要注册微信公众平台服务号,在开发=》接口权限=》网页授权
b.修改成自己的域名
c.Java微信公众号配置验证Token ==> https://blog.csdn.net/klo0704/article/details/93486616
注意:
其一 配置域名时不能填写https/http 若是顶级域名则不要填写www
其二 配置的项目如果又目论则要 在域名后跟随项目到根目录路径 无需跟随所要回调的页面的路径
其三 在配置之前要进行域名服务器校验,下载校验文件放于项目根目录即可
其四 前端redirect_uri一定要完整,http/https://域名项目路径/
在前端进行调用获取微信授权码

var redirectUrl = encodeURIComponent('https://域名/项目目录/')
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri='+ redirectUrl+'&response_type=code&scope=snsapi_base&connect_redirect=1#wechat_redirect'
二、获取useId
1.云闪付
/**
 * 云闪付获取用户userId
 * @param map
 * @return
 */
public String auth(Map<String, String> map)  {
    map.put("mid", PayConstants.mid);           // 商户号
    map.put("tid", PayConstants.tid);           // 终端号
    map.put("msgSrc", PayConstants.msgSrc);     // 请求来源
    map.put("msgSrcId", PayConstants.msgSrcId); // 来源Id
    map.put("msgType", "acp.getUserId");
    map.put("requestTimestamp", PayUtil.getTimestamp());     // 报文请求时间
    map.put("instMid", PayConstants.instMid);                // 业务类型
    map.put("sign", PayUtil.makeSign(PayConstants.md5 ,map));// MD5签名

    json = JSONObject.parseObject(JSON.toJSONString(map));
    String responseData = Httpkits.doPostJson1(PayConstants.unionPay_userAuth_url,json);
    return responseData;
}
2.微信:

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html

/**
 * 获取微信userid
 * @param code
 * @return
 */
public static String getWXAccessToken(String code) {
   StringBuilder sb = new StringBuilder();
   sb.append(WX_ACCESS_URL);
   sb.append("?appid="+ WX_APPID);
   sb.append("&secret="+ WX_SECRET);
   sb.append("&code="+ code);
   sb.append("&grant_type=authorization_code");
   String accessToken = Httpkits.doGet(sb.toString());
   JSONObject resp_json = JSONObject.parseObject(accessToken);
   return resp_json.getString("openid");
}
2.支付宝:

https://opendocs.alipay.com/open/284/web

/**
     * 获取支付宝userid
     * @param code
     * @return
     */
    public String auth(String code) {
        try {
            AlipayClient alipayClient = new DefaultAlipayClient( PayConstants.ALIPAY_SERVERURL, PayConstants.ALIPAY_APP_ID,
                    PayConstants.APP_PRIVATE_KEY,
                    "json",
                    "GBK",
                    PayConstants.ALIPAY_PUBLIC_KEY,
                    "RSA2");
            AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
            request.setGrantType("authorization_code");
            request.setCode(code);
            AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
            String data = JSON.toJSONString(response);
            JSONObject ret = JSONObject.parseObject(data);
            if(response.isSuccess()){
                return response.getUserId();
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return null;
    }
}
三、支付

下单按照云闪付所给的聚合支付下单流程进行操作

1、支付宝下单详见银联聚合支付下单API

成功后返回的支付宝订单信息在 jsPayRequest里
H5唤起支付前端引入支付的js https://opendocs.alipay.com/open/20180417160701241302/fqxh5v

<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>
ap.tradePay({
    tradeNO: res.jsPayRequest.orderNo, //从服务端获取订单号
}, function(res){
    console.log(res) // 支付宝下单支付后回调状态
});

如此支付宝即可下单成功

2、微信下单详见银联聚合支付下单API

微信下单 需要先将微信公众平台的APPID绑定至云闪付商户平台,然后通过云闪付文档注册微信小程序商户平台,再次把支付页面绑定至该商户平台(https/http://域名/项目路径/)
下单成功后 服务端会将微信订单信息回调至jsPayRequest
在前端调用

WeixinJSBridge.invoke(
'getBrandWCPayRequest', 
//{
//    "appId":"123123123",     //公众号名称,由商户传入     
//    "timeStamp":"1395712654",         //时间戳,自1970年以来的秒数     
//    "nonceStr":"e61463f8efa94090b1f366cccfbbb444", //随机串
//    "package":"prepay_id=u802345jgfjsdfgsdg888",     
//    "signType":"MD5",         //微信签名方式:     
//    "paySign":"70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 
//},//这些订单信息都在jsPayRequest之中
  res.jsPayRequest,
function(res){
    console.log('wxpay 支付回调', res)
 }
); 
3、云闪付下单详见银联聚合支付下单API

按照云闪付下单流程成功后会获取redirectUrl 然后

Window.location.href = redirectUrl 即可支付
三、文档详见云闪付聚合支付文档
四、文档、域名
需要联系云闪付开发人获取与配置
五、总结
1、授权code跟支付宝 、微信公众等平台H5授权一样
2、userid 也是在各大平台进行授权获取
3、无需在支付宝 微信等商户平台签约支付相关需求 可免除手续费
4、一码多用
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值