当前位置:   article > 正文

微信小程序支付——springboot——API_微信小程序开发使用spring boot的api

微信小程序开发使用spring boot的api

前端js

uni.request({
	url: that.urlPath + 'workfolder/toWeChatRequestPay',
	data: {
		body: that.copyrightOpusOrderinfo.sku_name,
		out_trade_no: that.copyrightOpusOrderinfo.order_sn,
		total_fee: parseInt(that.copyrightOpusOrderinfo.real_price*100),
		openid: uni.getStorageSync('self_user').openid,
		attach: 'WeChat'
	},
	method: 'GET',
	header: {
		'content-type': 'application/json'
	},
	success(res){
		// console.log(res.data)
		// console.log('prepay_id=' + res.data.prepay_id)
		//前去支付
		uni.requestPayment({
			timeStamp: res.data.timeStamp,
			nonceStr: res.data.nonce_str,
			package: 'prepay_id=' + res.data.prepay_id,
			signType: 'MD5',
			paySign: res.data.signKeyPay,
			success(res){
				// console.log(res.data)
				//支付成功,回调修改状态
				//that.updateCopyrightOpusOrder()
			},
			fail(error){
				console.log(error.errMsg)
				if (res.errMsg === 'requestPayment: fail cancel') {
					uni.showToast({
						title: '取消支付',
						icon: 'none'
					})
				} else {
					uni.showToast({
						title: '请重新支付',
						icon: 'none'
					})
				}
			}
		})
	}
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
@RequestMapping(value = "/toWeChatRequestPay" , method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public Map<String, String> toWeChatRequestPay(String body, String out_trade_no, String openid, String total_fee, String attach) {
        InetAddress addr = null;
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String spbill_create_ip = addr.getHostAddress();
        Map<String, String> auMap = new HashMap<>();
		auMap.put("appid", DataConfig.APPID);
		auMap.put("attach", attach);		
		auMap.put("body", body);	
		auMap.put("detail", "线上版权登记付款");
		auMap.put("mch_id", DataConfig.MCHID);//商户号
		auMap.put("nonce_str", WXPayUtil.generateNonceStr().toString());//随机数
		auMap.put("notify_url", "https://www.1ipr.top/yysipr_beta/workfolder");
		auMap.put("openid", openid);
		auMap.put("out_trade_no", out_trade_no);//商户订单号  Long.toString(System.currentTimeMillis())
		auMap.put("spbill_create_ip", spbill_create_ip);//订单生成的机器 IP
		auMap.put("total_fee", total_fee);//总金额
		auMap.put("trade_type", "JSAPI");
        try {
            String xmlParam = WXPayUtil.generateSignedXml(auMap, DataConfig.MCHID_KEY);
            // System.out.println(xmlParam);    
            HttpClientM client= new HttpClientM("https://api.mch.weixin.qq.com/pay/unifiedorder");
            client.setHttps(true);
            client.setXmlParam(xmlParam);
            client.post();
            String result = client.getContent();
            // System.out.println(result);    
            Document doc = DocumentHelper.parseText(result);//获取xml文件
            Element rootel = doc.getRootElement();//获取根目录
            // String prepay_id = rootel.elementText("prepay_id");
            auMap.put("prepay_id", rootel.elementText("prepay_id"));
            auMap.put("timeStamp", String.valueOf(Instant.now().getEpochSecond()));
            String signPay = "appId=" + auMap.get("appid") + "&nonceStr=" + auMap.get("nonce_str")
	            + "&package=prepay_id=" + rootel.elementText("prepay_id") + "&signType=" + "MD5"  + "&timeStamp=" + String.valueOf(Instant.now().getEpochSecond())
	            + "&key=" + DataConfig.MCHID_KEY;
            auMap.put("signKeyPay", new BigInteger(1, MessageDigest.getInstance("MD5").digest(signPay.getBytes())).toString(16).toUpperCase());
            // System.out.println(prepay_id);
            return auMap;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }finally{
            // sql = null;
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

WXPayUtil等微信sdk
微信支付java-sdk-v3.0.9

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/583747
推荐阅读
相关标签
  

闽ICP备14008679号