微信小程序支付(前端/java后端)

前端代码(uni-app)

let that = this;
    uni.login({
     success:function(res){
      if(res.code){
       that.$u.post('',{
        code: res.code
       }).then(res => {
        console.log(res)
        uni.requestPayment({
         provider: "wxpay",
         timeStamp: res.timeStamp,
         nonceStr: res.nonceStr,
         package: res.package,
         signType: res.signType,
         paySign: res.paySign,
         success: (response) => {
          uni.showToast({
           title: '支付成功',
           duration: 1500
          });
         },
         fail: (err) => {
          uni.showToast({
           title: '支付失败',
           icon: 'none'
          });
         }
        });
       })
      }
     }
    })


     

后端

                //通过code、appid、secret获取
                String temp = HttpUtils.sendGet(url, openidget);
                Map<String, Object> unionidMap = (Map<String, Object>) JSON.parse(temp);
                String openid = (String) unionidMap.get("openid");//拿openid
                MyWxConfig config = new MyWxConfig(appid); //微信支付配置类
                WXPay pay = new WXPay(config);
                Map<String, String> param = new HashMap<>();
                param.put("appid", appid);
                param.put("mch_id", config.getMchID());
                param.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
                param.put("body", content);
                param.put("out_trade_no", oid);
                param.put("total_fee",fee);
                param.put("openid", openid);
                param.put("attach", "测试中");
                param.put("sign", wxSign(param, config.getKey()));
                param.put("spbill_create_ip", getClientIP(request));   //终端IP
                param.put("notify_url", "http://lnfc.vip/api/wxNotify");
//              param.put("notify_url", "http://u38455l599.zicp.vip/api/wxNotify");
                param.put("trade_type", "JSAPI");  //交易类型
                System.out.println("支付完毕准备回调");
                Map<String, String> res = pay.unifiedOrder(param);
                System.out.println(res);
                Map<String, String> result = new HashMap<>();
                result.put("appId", appid);
                result.put("timeStamp", (new Date().getTime() / 1000) + "");
                result.put("nonceStr", RandomStringUtils.randomAlphanumeric(32));
                System.out.println("prepay_id="+res.get("prepay_id"));
                result.put("package", "prepay_id=" + res.get("prepay_id"));
                result.put("signType", "MD5");
                result.put("paySign", wxSign(result, config.getKey()));

其他具体业务具体分析

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值