| | |
| | | package com.ruoyi.other.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | |
| | | import com.ruoyi.other.util.ObsUploadUtil; |
| | | import com.ruoyi.other.util.QRCodeUtil; |
| | | import com.ruoyi.other.util.UUIDUtil; |
| | | import com.ruoyi.other.util.pay.CreateLinkStringByGet1; |
| | | import com.ruoyi.other.util.pay.HttpRequester; |
| | | import com.ruoyi.other.util.pay.HttpRespons; |
| | | import com.ruoyi.other.util.pay.Md5_Sign; |
| | | import com.ruoyi.other.util.payment.wx.WechatPayService; |
| | | import com.ruoyi.other.vo.IntegralListVO; |
| | | import com.ruoyi.other.vo.IntegralVO; |
| | | import com.ruoyi.other.vo.PayDto; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | integralVO.setIntegral(integral); |
| | | return R.ok(integralVO); |
| | | } |
| | | @PostMapping("/queryPayStatus") |
| | | |
| | | @ApiOperation(tags = {"2.0-积分钱包"},value = "查询支付结果 true成功 false失败") |
| | | public R<Boolean> integralPageList(@RequestParam("code") String code) throws Exception { |
| | | Map<String, String> resMap = wechatPayService.queryOrder(code); |
| | | if("SUCCESS".equals(resMap.get("return_code"))){ |
| | | @PostMapping(value = "/queryPayStatus") |
| | | public R buy(@RequestParam Integer id) { |
| | | IntegralPay integralPay = integralPayService.getById(id); |
| | | if (integralPay.getPayStatus()==2){ |
| | | return R.ok(true); |
| | | }else{ |
| | | }else { |
| | | return R.ok(false); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/nativePay") |
| | | @ApiOperation(tags = {"2.0-积分钱包"},value = "获取支付二维码") |
| | | public R nativePay(@RequestParam("amount") String amount) throws Exception { |
| | | public R<PayDto> nativePay(@RequestParam("amount") String amount) throws Exception { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | Map<String, String> res = wechatPayService.unifiedOrder(code, amount, "积分充值", "/other/wx/integralCallback"); |
| | | // Map<String, String> res = wechatPayService.unifiedOrder(code, amount, "积分充值", "/other/wx/integralCallback"); |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | R<SysUser> sysUser = sysUserClient.getSysUser(userid); |
| | | SysUser data = sysUser.getData(); |
| | |
| | | integralPay.setDelFlag(0); |
| | | integralPay.setCreateTime(LocalDateTime.now()); |
| | | integralPayService.save(integralPay); |
| | | String codeUrl = res.get("code_url"); |
| | | MyQrCodeUtil.createCodeToFile(codeUrl); |
| | | BufferedImage blueImage = QRCodeUtil.createImage(codeUrl); |
| | | MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | String s = ObsUploadUtil.obsUpload(blueFile); |
| | | System.err.println(s); |
| | | return R.ok(s); |
| | | // String codeUrl = res.get("code_url"); |
| | | // MyQrCodeUtil.createCodeToFile(codeUrl); |
| | | // BufferedImage blueImage = QRCodeUtil.createImage(codeUrl); |
| | | // MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | // String s = ObsUploadUtil.obsUpload(blueFile); |
| | | // System.err.println(s); |
| | | int money = new BigDecimal(amount).multiply(BigDecimal.valueOf(100)).intValue(); |
| | | 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("p5_ProductName", "充值"); /** 商品名称 */ |
| | | map.put("p6_ProductDesc", "积分充值"); /** 商品名称 */ |
| | | // map.put("p7_Mp", ""); /** 如果商户请求时传递了该参数,则返回给商户时会原值传 回。 */ |
| | | map.put("p9_NotifyUrl", "http://221.182.45.100:8084/other/wx/integralCallback"); /** 服务器异步通知地址 */ |
| | | map.put("q1_FrpCode", "WEIXIN_NATIVE"); /** 微信扫码(主扫)【注:此为用户主扫,商户被扫】*/ |
| | | map.put("q4_IsShowPic", "1"); /** 是否展示二 维码图片 1表示输出*/ |
| | | map.put("q7_AppId", "wx1a4a7760be53a835"); /** 交易类型*/ |
| | | map.put("qa_TradeMerchantNo", "777165000859101"); /** 777开头的报备商户号 必填!*/ |
| | | map.put("qi_FqSellerPercen", "0"); /** 卖家承担收 费比例 目前仅支持传入 0 ,即用户承 担手续费!*/ |
| | | 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://trade.joinpay.com/tradeRt/uniPay", map); |
| | | System.out.println("接收返回参数:" + HP.getContent()); |
| | | JSONObject resPay = JSONObject.parseObject(HP.getContent()); |
| | | String rcResult = resPay.getString("rd_Pic"); |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("rcResult", rcResult); |
| | | PayDto payDto = new PayDto(); |
| | | payDto.setId(integralPay.getId()); |
| | | payDto.setQrCode(rcResult); |
| | | return R.ok(payDto); |
| | | } |
| | | |
| | | public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException { |
| | | // 将 BufferedImage 转换为字节数组 |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |