| | |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.builder.ExcelWriterBuilder; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | |
| | | import com.ruoyi.admin.service.*; |
| | | import com.ruoyi.admin.utils.MD5AndKL; |
| | | import com.ruoyi.admin.utils.WeChatUtil; |
| | | import com.ruoyi.admin.utils.util.CreateLinkStringByGet1; |
| | | import com.ruoyi.admin.utils.util.HttpRequester; |
| | | import com.ruoyi.admin.utils.util.HttpRespons; |
| | | import com.ruoyi.admin.utils.util.Md5_Sign; |
| | | import com.ruoyi.admin.vo.InfoDto; |
| | | import com.ruoyi.admin.vo.MoneyRecentQuery; |
| | | import com.ruoyi.admin.vo.PayDto; |
| | |
| | | |
| | | @ApiOperation(value = "js支付", tags = {"2.0-支付"}) |
| | | @GetMapping(value = "/js/wxPay") |
| | | public R jsPay(@RequestParam String openId,@RequestParam BigDecimal money,@RequestParam Integer userId) { |
| | | public R jsPay(@RequestParam String openId,@RequestParam BigDecimal money,@RequestParam Integer userId) throws IOException { |
| | | SysUser byId1 = sysUserService.getById(userId); |
| | | this.privateKey = PemUtil.loadPrivateKey(getPrivateKeyStream()); |
| | | this.privateKeySigner = new PrivateKeySigner(weChatConfig.merchantSerialNumber, privateKey); |
| | |
| | | Franchisee byId = franchiseeService.getById(byId1.getFranchiseeId()); |
| | | |
| | | |
| | | PrepayRequest prepayRequest = new PrepayRequest(); |
| | | prepayRequest.setAppid(weChatConfig.appId); |
| | | prepayRequest.setMchid(weChatConfig.merchantId); |
| | | prepayRequest.setDescription("加盟商充值"); |
| | | prepayRequest.setOutTradeNo(code); |
| | | prepayRequest.setNotifyUrl("http://www.zhipingwang.com.cn:9090/admin/franchisee/callBack"); |
| | | Amount amount = new Amount(); |
| | | amount.setTotal(i); |
| | | prepayRequest.setAmount(amount); |
| | | Payer payer = new Payer(); |
| | | payer.setOpenid(openId); |
| | | prepayRequest.setPayer(payer); |
| | | PrepayResponse prepay = jsapiService.prepay(prepayRequest); |
| | | String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); |
| | | String packageStr = "prepay_id=" + prepay.getPrepayId(); |
| | | // |
| | | String key = "ad273ceb5e1b49e68d5c565d28d1d305";/** md5密钥商户后台-商户中心-商户设置-密钥管理获取 必填!*/ |
| | | Map<String, String> map = new HashMap<String, String>(); |
| | | map.put("p0_Version", "2.5");/** 版本号 */ |
| | | map.put("p1_MerchantNo", "888122400007793");/** 商户编号 */ |
| | | map.put("p2_OrderNo", code); /**商户订单号*/ |
| | | map.put("p3_Amount", String.valueOf(money));/**订单金额*/ |
| | | map.put("p4_Cur", "1"); /**交易币种 */ |
| | | map.put("q5_OpenId", openId); |
| | | map.put("p5_ProductName", "加盟商充值"); /** 商品名称 */ |
| | | map.put("p9_NotifyUrl", "http://www.zhipingwang.com.cn:9100/admin/franchisee/callBack"); /** 服务器异步通知地址 */ |
| | | map.put("q1_FrpCode", "WEIXIN_APP3"); /** 交易类型*/ |
| | | map.put("q7_AppId", "wx1a4a7760be53a835"); /** 交易类型*/ |
| | | map.put("qa_TradeMerchantNo", "777165000859101"); /** 777开头的报备商户号 必填!*/ |
| | | |
| | | String prepay_id = prepay.getPrepayId(); |
| | | //重新进行签名后返回给前端 |
| | | String Strmap = CreateLinkStringByGet1.createLinkStringByGet(map); |
| | | |
| | | // 签名 |
| | | String sign = ""; |
| | | sign = Md5_Sign.SignByMD5(Strmap, key); |
| | | map.put("hmac", sign);/** 签名数据 */ |
| | | System.out.println("发送:" + JSON.toJSONString(map).toString()); |
| | | |
| | | // post请求参数内容 |
| | | HttpRequester hr = new HttpRequester(); |
| | | HttpRespons HP = hr.sendPost("https://www.joinpay.com/trade/uniPayApi.action", map); |
| | | System.out.println("接收返回参数:" + HP.getContent()); |
| | | JSONObject jsonObject = JSONObject.parseObject(HP.getContent()); |
| | | JSONObject rcResult = JSONObject.parseObject(jsonObject.getString("rc_Result")); |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("appid", weChatConfig.getAppId()); |
| | | map2.put("noncestr", code); |
| | | map2.put("package", "Sign=WXPay"); |
| | | map2.put("partnerid", weChatConfig.getMerchantId()); |
| | | map2.put("prepayid", prepay_id); |
| | | map2.put("timestamp", timeStamp); |
| | | // String s1 = this.weixinSignature(map2); |
| | | String signStr = Stream.of(weChatConfig.getAppId(), timeStamp, code, packageStr).collect(Collectors.joining("\n", "", "\n")); |
| | | String packageSign = privateKeySigner.sign(signStr.getBytes(StandardCharsets.UTF_8)).getSign(); |
| | | map2.put("rcResult", rcResult); |
| | | // map2.put("timestamp", rcResult.get("timeStamp")); |
| | | // map2.put("prepayid", rcResult.get("package")); |
| | | // map2.put("sign", rcResult.get("paySign")); |
| | | |
| | | map2.put("sign", packageSign); |
| | | System.err.println(map2); |
| | | // |
| | | // PrepayRequest prepayRequest = new PrepayRequest(); |
| | | // prepayRequest.setAppid(weChatConfig.appId); |
| | | // prepayRequest.setMchid(weChatConfig.merchantId); |
| | | // prepayRequest.setDescription("加盟商充值"); |
| | | // prepayRequest.setOutTradeNo(code); |
| | | // prepayRequest.setNotifyUrl("http://www.zhipingwang.com.cn:9090/admin/franchisee/callBack"); |
| | | // Amount amount = new Amount(); |
| | | // amount.setTotal(i); |
| | | // prepayRequest.setAmount(amount); |
| | | // Payer payer = new Payer(); |
| | | // payer.setOpenid(openId); |
| | | // prepayRequest.setPayer(payer); |
| | | // PrepayResponse prepay = jsapiService.prepay(prepayRequest); |
| | | // String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); |
| | | // String packageStr = "prepay_id=" + prepay.getPrepayId(); |
| | | // |
| | | // String prepay_id = prepay.getPrepayId(); |
| | | // //重新进行签名后返回给前端 |
| | | |
| | | //// String s1 = this.weixinSignature(map2); |
| | | // String signStr = Stream.of(weChatConfig.getAppId(), timeStamp, code, packageStr).collect(Collectors.joining("\n", "", "\n")); |
| | | // String packageSign = privateKeySigner.sign(signStr.getBytes(StandardCharsets.UTF_8)).getSign(); |
| | | // |
| | | // System.err.println(map2); |
| | | |
| | | |
| | | TFranchiseeBalanceChange tFranchiseeBalanceChange = new TFranchiseeBalanceChange(); |
| | |
| | | @ApiOperation(value = "支付回调",tags = {"微信支付回调"}) |
| | | @RequestMapping (value = "/callBack") |
| | | @Transactional |
| | | public R payNotify(HttpServletRequest request) throws Exception{ |
| | | public R payNotify(HttpServletRequest request,String r2_OrderNo) throws Exception{ |
| | | System.err.println("======回调开始"); |
| | | Transaction transaction; |
| | | transaction = notificationParser.parse(WeChatUtil.handleNodifyRequestParam(request), Transaction.class); |
| | | if (transaction.getTradeState() == Transaction.TradeStateEnum.SUCCESS) { |
| | | System.err.println("======回调开始"+r2_OrderNo); |
| | | // Transaction transaction; |
| | | // transaction = notificationParser.parse(WeChatUtil.handleNodifyRequestParam(request), Transaction.class); |
| | | // if (transaction.getTradeState() == Transaction.TradeStateEnum.SUCCESS) { |
| | | //将记录变为已支付 |
| | | TFranchiseeBalanceChange one = balanceChangeService.lambdaQuery().eq(TFranchiseeBalanceChange::getCode, transaction.getOutTradeNo()).one(); |
| | | TFranchiseeBalanceChange one = balanceChangeService.lambdaQuery().eq(TFranchiseeBalanceChange::getCode,r2_OrderNo).one(); |
| | | if (one.getIs_pay()==0) { |
| | | //将加盟商的余额增加 |
| | | Franchisee byId = franchiseeService.getById(one.getFranchiseeId()); |
| | |
| | | one.setIs_pay(1); |
| | | balanceChangeService.updateById(one); |
| | | |
| | | } |
| | | // } |
| | | |
| | | } |
| | | return R.ok(null,"SUCCESS"); |