| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.agentdriving.user.modular.system.model.*; |
| | | import com.agentdriving.user.modular.system.service.*; |
| | | import com.agentdriving.user.modular.system.util.MallBook.model.InterfaceResponse; |
| | | import com.agentdriving.user.modular.system.util.MallBook.model.PaymentOrder; |
| | | import com.agentdriving.user.modular.system.util.MallBook.model.PaymentOrderGood; |
| | | import com.agentdriving.user.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.agentdriving.user.modular.system.util.PayMoneyUtil; |
| | | import com.agentdriving.user.modular.system.util.RedisUtil; |
| | | import com.agentdriving.user.modular.system.util.ResultUtil; |
| | |
| | | import com.agentdriving.user.modular.system.util.weChat.WXCore; |
| | | import com.agentdriving.user.modular.system.util.weChat.WeChatUtil; |
| | | import com.agentdriving.user.modular.system.util.weChat.model.Code2Session; |
| | | import com.agentdriving.user.modular.system.warpper.*; |
| | | import org.apache.shiro.authc.SimpleAuthenticationInfo; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; |
| | |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | |
| | | rechargeRecord.setPayStatus(1); |
| | | rechargeRecord.setPayType(1); |
| | | rechargeRecordService.insert(rechargeRecord); |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/appUser/rechargeBalanceCallback", "JSAPI", appUser.getOpenid()); |
| | | // return weixinpay; |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/appUser/rechargeBalanceCallback", "JSAPI", appUser.getOpenid()); |
| | | if(weixinpay.getCode() == 200){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | RechargeRecord rechargeRecord1 = rechargeRecordService.selectById(rechargeRecord.getId()); |
| | | if (rechargeRecord1.getPayStatus() == 2) { |
| | | return; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | if (resultUtil.getCode() == 200) { |
| | | /** |
| | | * 订单状态 |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data2 = resultUtil.getData(); |
| | | String s = data2.get("state"); |
| | | String transaction_id = data2.get("transaction_id"); |
| | | if ("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s)) { |
| | | //回退 |
| | | return; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | rechargeRecord1.setPayStatus(2); |
| | | rechargeRecord1.setPayTime(new Date()); |
| | | rechargeRecord1.setOrderNumber(transaction_id); |
| | | rechargeRecordService.updateById(rechargeRecord1); |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(amount * 100)); |
| | | paymentOrder.setOrderName("余额充值"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(appletsAppid); |
| | | paymentOrder.setOpenid(appUser.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("余额充值"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(""); |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/appUser/rechargeBalanceCallback"); |
| | | paymentOrder.setParameter1(out_trade_no); |
| | | |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | AppUser appUser1 = AppUserServiceImpl.this.selectById(rechargeRecord1.getUserId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(appUser1.getId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(appUser1.getAccountBalance()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(3); |
| | | accountChangeDetail.setExplain("余额充值"); |
| | | appUser1.setAccountBalance(appUser1.getAccountBalance() + rechargeRecord1.getAmount()); |
| | | accountChangeDetail.setNewData(appUser1.getAccountBalance()); |
| | | AppUserServiceImpl.this.updateById(appUser1); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | if ("USERPAYING".equals(s)) { |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | }else{ |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | String payCode = jsonObject.getString("payCode"); |
| | | return ResultUtil.success(payCode); |
| | | if(10 == num){ |
| | | rechargeRecordService.deleteById(rechargeRecord1.getId()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return weixinpay; |
| | | } |
| | | |
| | | |