【微信小程序付款转二维码付款】

该代码实现了一个小程序支付的过程,首先通过sessionId获取订单数据,然后利用获取的uuid生成二维码。主要涉及的参数有:sessionId、timeStamp、nonceStr、package、paySign、appid等,最终调用接口生成支付二维码。
摘要由CSDN通过智能技术生成

需要的参数:session_id, timeStamp, nonceStr, package, paySign, appid,uuid
session_id是协议获取
timeStamp, nonceStr, package, paySign, appid是订单数据
uuid是调用接口获取

  1. 第一步要获取小程序的sessionId 基于pc协议不风控
    pc协议
  2. 获取订单数据timeStamp, nonceStr, package, paySign, appid
    调用https://open.weixin.qq.com/wxaruntime/getuuid?session_id= 获取uuid
  3. 调用接口获取到的uuid拼接https://api.weixin.qq.com/wxaruntime/readqrcode?uuid=转二维码

代码奉上

public String pay(String appId,String timeStamp,String nonceStr,String packages,String paySign,String sessionId){
        Map<String, Object> map = new HashMap<>();
        map.put("adUxInfo","");
        map.put("provider","wxpay");
        map.put("timeStamp",timeStamp);
        map.put("nonceStr",nonceStr);
        map.put("package",packages);
        map.put("paySign",paySign);
        map.put("signType","MD5");
        map.put("cookie","busid=wxapp; appid="+appId+";; busid=wxapp; sessionid=;; busid=wxapp; scene=1001;; busid=wxapp; scene_note=");
        map.put("grantMessageQuota",true);
        Map<String, Object> map1 = new HashMap<>();
        map1.put("args", JSON.toJSONString(map));
        map1.put("isBridgedJsApi",true);
        map1.put("jsapiType","appservice");
        map1.put("miniprogramAppID",appId);
        map1.put("name","requestPayment");
        map1.put("transitiveData","");
        Map<String, Object> map2 = new HashMap();
        map2.put("invokeData",JSON.toJSONString(map1));
        map2.put("pathType",1);
        map2.put("rumtimeAppid",appId);
        map2.put("runtimeSessionId",sessionId);
        map2.put("runtimeTicket","Product");
        Map<String, Object> map3 = new HashMap<>();
        map3.put("appid",appId);
        map3.put("req_data",JSON.toJSONString(map2));
        String body = HttpRequest.post("https://open.weixin.qq.com/wxaruntime/getuuid?session_id=" + sessionId)
                .body(JSONObject.toJSONString(map3))
                .header("Host","open.weixin.qq.com")
                .header("Accept","*/*")
                .header("Content-Type","application/x-www-form-urlencoded")
                .header("Expect","100-continue")
                .execute().body();
        if (!StrUtil.contains(body,"uuid")){
            return null;
        }
        return QrCodeUtil.generateAsBase64("https://api.weixin.qq.com/wxaruntime/readqrcode?uuid="
                + JSONObject.parseObject(body).getString("uuid"), new QrConfig(300,300), "jpg");

    }
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值