| | |
| | | import com.supersavedriving.user.modular.system.util.MallBook.model.PaymentOrder; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.model.PaymentOrderGood; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.model.QueryOrder; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.util.Transfer; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.supersavedriving.user.modular.system.util.PayMoneyUtil; |
| | | import com.supersavedriving.user.modular.system.util.RedisUtil; |
| | |
| | | |
| | | @Autowired |
| | | private IAccountChangeDetailService accountChangeDetailService; |
| | | |
| | | @Autowired |
| | | private IDriverService driverService; |
| | | |
| | | @Autowired |
| | | private ISystemConfigService systemConfigService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath;//支付回调网关地址 |
| | |
| | | @Override |
| | | public ResultUtil<SignInToRegisterWarpper> signInToRegister(SignInToRegister signInToRegister) throws Exception { |
| | | SignInToRegisterWarpper warpper = new SignInToRegisterWarpper(); |
| | | if(ToolUtil.isEmpty(signInToRegister.getJscode())){ |
| | | return ResultUtil.paranErr("jscode"); |
| | | } |
| | | if(ToolUtil.isEmpty(signInToRegister.getEncryptedDataPhone())){ |
| | | return ResultUtil.paranErr("encryptedDataPhone"); |
| | | } |
| | | if(ToolUtil.isEmpty(signInToRegister.getIvPhone())){ |
| | | return ResultUtil.paranErr("ivPhone"); |
| | | } |
| | | Code2Session code2Session = weChatUtil.code2Session(signInToRegister.getJscode()); |
| | | if(null != code2Session.getErrcode() && code2Session.getErrcode() != 0){ |
| | | return ResultUtil.error(code2Session.getErrmsg()); |
| | | } |
| | | String openid = code2Session.getOpenid(); |
| | | String session_key = code2Session.getSession_key(); |
| | | String decrypt = WXCore.decrypt(signInToRegister.getEncryptedDataPhone(), session_key, signInToRegister.getIvPhone()); |
| | | if(ToolUtil.isEmpty(decrypt)){ |
| | | return ResultUtil.error("获取手机号失败"); |
| | | } |
| | | JSONObject phone = JSON.parseObject(decrypt); |
| | | String purePhoneNumber = phone.getString("purePhoneNumber"); |
| | | AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("phone", purePhoneNumber).ne("status", 3)); |
| | | if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setNickname("亲爱的用户"); |
| | | appUser.setAvatar("https://csxdj.obs.cn-south-1.myhuaweicloud.com:443/66cc269703a84e4da87fb21e2c21ab1f.png"); |
| | | appUser.setPhone(purePhoneNumber); |
| | | appUser.setOpenid(openid); |
| | | appUser.setUnionid(code2Session.getUnionid()); |
| | | appUser.setAccountBalance(0D); |
| | | appUser.setStatus(1); |
| | | appUser.setCreateTime(new Date()); |
| | | appUser.setIsException(1); |
| | | appUser.setInviterId(signInToRegister.getInviterId()); |
| | | appUser.setInviterType(signInToRegister.getInviterType()); |
| | | this.insert(appUser); |
| | | //发送优惠券 |
| | | boolean lock = redisUtil.lock(); |
| | | if(lock){ |
| | | List<CouponWarpper> list = pushCoupon(appUser.getId()); |
| | | redisUtil.unlock(); |
| | | warpper.setCoupons(list); |
| | | try { |
| | | if(ToolUtil.isEmpty(signInToRegister.getJscode())){ |
| | | return ResultUtil.paranErr("jscode"); |
| | | } |
| | | if(ToolUtil.isEmpty(signInToRegister.getEncryptedDataPhone())){ |
| | | return ResultUtil.paranErr("encryptedDataPhone"); |
| | | } |
| | | if(ToolUtil.isEmpty(signInToRegister.getIvPhone())){ |
| | | return ResultUtil.paranErr("ivPhone"); |
| | | } |
| | | Code2Session code2Session = weChatUtil.code2Session(signInToRegister.getJscode()); |
| | | if(null != code2Session.getErrcode() && code2Session.getErrcode() != 0){ |
| | | return ResultUtil.error(code2Session.getErrmsg()); |
| | | } |
| | | String openid = code2Session.getOpenid(); |
| | | String session_key = code2Session.getSession_key(); |
| | | String decrypt = WXCore.decrypt(signInToRegister.getEncryptedDataPhone(), session_key, signInToRegister.getIvPhone()); |
| | | if(ToolUtil.isEmpty(decrypt)){ |
| | | return ResultUtil.error("获取手机号失败"); |
| | | } |
| | | JSONObject phone = JSON.parseObject(decrypt); |
| | | String purePhoneNumber = phone.getString("purePhoneNumber"); |
| | | AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("phone", purePhoneNumber).ne("status", 3)); |
| | | if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setNickname("亲爱的用户"); |
| | | appUser.setAvatar("https://csxdj.obs.cn-south-1.myhuaweicloud.com:443/66cc269703a84e4da87fb21e2c21ab1f.png"); |
| | | appUser.setPhone(purePhoneNumber); |
| | | appUser.setOpenid(openid); |
| | | appUser.setUnionid(code2Session.getUnionid()); |
| | | appUser.setAccountBalance(0D); |
| | | appUser.setStatus(1); |
| | | appUser.setCreateTime(new Date()); |
| | | appUser.setIsException(1); |
| | | appUser.setInviterId(signInToRegister.getInviterId()); |
| | | appUser.setInviterType(signInToRegister.getInviterType()); |
| | | this.insert(appUser); |
| | | //发送优惠券 |
| | | boolean lock = redisUtil.lock(); |
| | | if(lock){ |
| | | List<CouponWarpper> list = pushCoupon(appUser.getId()); |
| | | redisUtil.unlock(); |
| | | warpper.setCoupons(list); |
| | | } |
| | | } |
| | | if(appUser.getStatus() == 2){ |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | String token = getToken(appUser); |
| | | if(ToolUtil.isEmpty(token)){ |
| | | return ResultUtil.error("获取身份凭证失败"); |
| | | } |
| | | warpper.setToken(token); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | redisUtil.unlock(); |
| | | } |
| | | if(appUser.getStatus() == 2){ |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | String token = getToken(appUser); |
| | | if(ToolUtil.isEmpty(token)){ |
| | | return ResultUtil.error("获取身份凭证失败"); |
| | | } |
| | | warpper.setToken(token); |
| | | return ResultUtil.success(warpper); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 转账 |
| | | * @param id |
| | | * @param merOrderId |
| | | * @param toUserId |
| | | * @param amount |
| | | * @param notifyUrl |
| | | * @return |
| | | */ |
| | | public ResultUtil zhaunzhang(Integer id, String merOrderId, String toUserId, Double amount, String notifyUrl){ |
| | | Transfer transfer = new Transfer(); |
| | | transfer.setDepositMerOrderId(merOrderId); |
| | | transfer.setToUserId(toUserId); |
| | | transfer.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | transfer.setOrderName("补贴"); |
| | | transfer.setNotifyUrl(notifyUrl); |
| | | transfer.setParameter1(id.toString()); |
| | | TrhRequest<Transfer> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(transfer, Transfer.SERVICE_CODE); |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | Integer status = jsonObject.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(2 == status){ |
| | | System.err.println("转账失败"); |
| | | return ResultUtil.error("转账失败"); |
| | | } |
| | | return ResultUtil.success(); |
| | | }else{ |
| | | System.err.println("转账失败:" + execute.getMsg()); |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(amount * 100)); |
| | | paymentOrder.setAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | paymentOrder.setOrderName("账户充值"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |