|
@@ -0,0 +1,197 @@
|
|
|
+package com.zswl.cloud.springBtach.server.core.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.github.microservice.auth.client.content.ResultContent;
|
|
|
+import com.github.microservice.auth.client.content.ResultState;
|
|
|
+import com.github.microservice.auth.client.model.UserAuthModel;
|
|
|
+import com.github.microservice.auth.client.model.UserModel;
|
|
|
+import com.github.microservice.auth.client.service.UserService;
|
|
|
+import com.github.microservice.auth.client.type.LoginType;
|
|
|
+import com.zhongshu.payment.client.model.order.v2.CreatOrderResultModel;
|
|
|
+import com.zhongshu.payment.client.model.order.v2.CreateOrder2Model;
|
|
|
+import com.zhongshu.payment.client.model.payment.CreateResponseModel;
|
|
|
+import com.zhongshu.payment.client.model.payment.zswl.CreatePayment2Model;
|
|
|
+import com.zhongshu.payment.client.service.v2.OrderService2;
|
|
|
+import com.zhongshu.payment.client.service.v2.PaymentService2;
|
|
|
+import com.zhongshu.payment.client.type.Channel;
|
|
|
+import com.zhongshu.payment.client.type.JobFlowMap;
|
|
|
+import com.zhongshu.payment.client.type.TransferOwner;
|
|
|
+import com.zhongshu.payment.client.type.TransferType;
|
|
|
+import com.zswl.cloud.shop.client.service.ShopService;
|
|
|
+import com.zswl.cloud.shop.client.vo.life.AccountDetailVo;
|
|
|
+import com.zswl.cloud.shop.client.vo.life.SharePlatformVo;
|
|
|
+import com.zswl.cloud.springBatch.client.model.recharge.RechargeCreateModel;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.tomcat.util.buf.HexUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class RechargeServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrderService2 orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaymentService2 paymentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ShopService shopService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ public ResultContent recharge(RechargeCreateModel rechargeCreateModel) {
|
|
|
+ String verification = verification(JSONUtil.parseObj(rechargeCreateModel));
|
|
|
+ if (!verification.equals(rechargeCreateModel.getSign())) {
|
|
|
+ return ResultContent.build(ResultState.Fail, "验签失败");
|
|
|
+ }
|
|
|
+ String phone = rechargeCreateModel.getPhone();
|
|
|
+ String shopName = rechargeCreateModel.getShopName();
|
|
|
+ BigDecimal totalAmount = rechargeCreateModel.getTotalAmount();
|
|
|
+ String goodsName = rechargeCreateModel.getGoodsName();
|
|
|
+ String goodsPath = rechargeCreateModel.getGoodsPath();
|
|
|
+ String orderDesc = rechargeCreateModel.getOrderDesc();
|
|
|
+ String subOpenId = rechargeCreateModel.getSubOpenId();
|
|
|
+
|
|
|
+ JSONObject goodsJson = rechargeCreateModel.getGoodsInfo();
|
|
|
+ JSONObject shopInfo = rechargeCreateModel.getShopInfo();
|
|
|
+
|
|
|
+ ResultContent<UserModel> userModelResultContent = userService.queryFromLoginType(LoginType.Phone, phone);
|
|
|
+ String userId;
|
|
|
+ if (!userModelResultContent.getState().equals(ResultState.Success)) {
|
|
|
+ UserAuthModel userAuthModel = new UserAuthModel();
|
|
|
+ userAuthModel.setLoginType(LoginType.Phone);
|
|
|
+ userAuthModel.setLoginValue(phone);
|
|
|
+ userAuthModel.setPassWord(phone);
|
|
|
+ ResultContent<String> add = userService.add(userAuthModel);
|
|
|
+ userId = add.getContent();
|
|
|
+ } else {
|
|
|
+ userId = userModelResultContent.getContent().getUserId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ com.zswl.cloud.shop.client.ret.ResultContent<AccountDetailVo> shopSetting = shopService.shopSetting("充电");
|
|
|
+ if (!shopSetting.getState().equals(com.zswl.cloud.shop.client.ret.ResultState.Success)) {
|
|
|
+ return ResultContent.build(ResultState.Fail, "充电");
|
|
|
+ }
|
|
|
+ AccountDetailVo accountDetailVo = shopSetting.getContent();
|
|
|
+ // 分账信息
|
|
|
+ String shopId = accountDetailVo.getAccountId();
|
|
|
+ String authAccount = accountDetailVo.getAuthAccount();
|
|
|
+ SharePlatformVo sharePlatformVo = accountDetailVo.getSharePlatformVo();
|
|
|
+
|
|
|
+
|
|
|
+ shopInfo.set("shopName", shopName);
|
|
|
+ CreateOrder2Model createOrder2Model = new CreateOrder2Model();
|
|
|
+ createOrder2Model.setUserId(userId);
|
|
|
+ createOrder2Model.setShopId(shopId);
|
|
|
+ createOrder2Model.setShopInfo(shopInfo);
|
|
|
+ createOrder2Model.setTotalAmount(totalAmount);
|
|
|
+ createOrder2Model.setDiscountAmount(BigDecimal.ZERO);
|
|
|
+ createOrder2Model.setPayAmount(totalAmount);
|
|
|
+ createOrder2Model.setAccesserUserId(authAccount);
|
|
|
+ createOrder2Model.setChannel(Channel.GuiDa);
|
|
|
+ goodsJson.set("goodsName", goodsName);
|
|
|
+ goodsJson.set("goodsPath", goodsPath);
|
|
|
+ CreateOrder2Model.Goods goods = new CreateOrder2Model.Goods();
|
|
|
+ goods.setJobFlowMap(JobFlowMap.ChongDian);
|
|
|
+ goods.setGoodsInfo(goodsJson);
|
|
|
+ goods.setPayAmount(totalAmount);
|
|
|
+ goods.setTransferType(TransferType.RATIO);
|
|
|
+ List<CreateOrder2Model.Owner> ownerList = new ArrayList<>();
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner platfor = new CreateOrder2Model.Owner();
|
|
|
+ platfor.setOwner(TransferOwner.PLATFORM);
|
|
|
+ platfor.setValue(sharePlatformVo.getPlatformRate());
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner buy = new CreateOrder2Model.Owner();
|
|
|
+ buy.setOwner(TransferOwner.BUY_SHOP);
|
|
|
+ buy.setValue(sharePlatformVo.getBuyShopRate());
|
|
|
+ buy.setShopId(shopId);
|
|
|
+
|
|
|
+ CreateOrder2Model.Owner use = new CreateOrder2Model.Owner();
|
|
|
+ use.setOwner(TransferOwner.USE_SHOP);
|
|
|
+ use.setValue(sharePlatformVo.getCheckShopRate());
|
|
|
+
|
|
|
+ ownerList.add(platfor);
|
|
|
+ ownerList.add(buy);
|
|
|
+ ownerList.add(use);
|
|
|
+ goods.setTransferRrule(ownerList);
|
|
|
+ createOrder2Model.setGoodsList(List.of(goods));
|
|
|
+
|
|
|
+
|
|
|
+ ResultContent<CreatOrderResultModel> creat = orderService.creat(createOrder2Model);
|
|
|
+
|
|
|
+ CreatePayment2Model createPayment2Model = new CreatePayment2Model();
|
|
|
+ createPayment2Model.setAuthUserId(userId);
|
|
|
+ createPayment2Model.setOrderNo(creat.getContent().getOrderNo());
|
|
|
+ createPayment2Model.setMsgType("wx.unifiedOrder");
|
|
|
+ createPayment2Model.setOrderDesc(orderDesc);
|
|
|
+ createPayment2Model.setSubOpenId(subOpenId);
|
|
|
+ ResultContent<CreateResponseModel> createResponseModelResultContent = paymentService.creatPayOrder(createPayment2Model);
|
|
|
+
|
|
|
+ return createResponseModelResultContent;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String verification(JSONObject entries) {
|
|
|
+ TreeMap<String, Object> map = new TreeMap<>();
|
|
|
+
|
|
|
+ for (String key : entries.keySet()) {
|
|
|
+ Object value = entries.get(key);
|
|
|
+
|
|
|
+ if (!ObjectUtil.isEmpty(value) && !"sign".equals(key)) {
|
|
|
+ map.put(key, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
+
|
|
|
+ for (String s : map.keySet()) {
|
|
|
+ if (stringBuffer.length() == 0) {
|
|
|
+ stringBuffer.append(s + "=" + String.valueOf(map.get(s)));
|
|
|
+ } else {
|
|
|
+ Object o = map.get(s);
|
|
|
+
|
|
|
+ if (o instanceof ArrayList) {
|
|
|
+
|
|
|
+ String jsonStr = JSONUtil.toJsonStr(o);
|
|
|
+ stringBuffer.append("&" + s + "=" + jsonStr);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ stringBuffer.append("&" + s + "=" + String.valueOf(map.get(s)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String s = signData(stringBuffer + "11111");
|
|
|
+
|
|
|
+ return s;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ public static String signData(String json_data) {
|
|
|
+ MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
|
+ md.reset();
|
|
|
+ md.update(json_data.getBytes("utf-8"));
|
|
|
+ return HexUtils.toHexString(md.digest());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|