|
@@ -0,0 +1,122 @@
|
|
|
|
+package com.book.server.service.impl;
|
|
|
|
+
|
|
|
|
+import com.book.dao.VO.PalmpayResponse;
|
|
|
|
+import com.book.dao.VO.WxPayInfo;
|
|
|
|
+import com.book.dao.VO.WxPayRequest;
|
|
|
|
+import com.book.dao.cps.entity.Goods;
|
|
|
|
+import com.book.dao.cps.mapper.AdminConfigMapper;
|
|
|
|
+import com.book.dao.cps.mapper.ConfigMapper;
|
|
|
|
+import com.book.dao.cps.mapper.GoodsMapper;
|
|
|
|
+import com.book.dao.cps.mapper.OphostMapper;
|
|
|
|
+import com.book.dao.cps.pojo.AdminConfig;
|
|
|
|
+import com.book.dao.cps.pojo.Config;
|
|
|
|
+import com.book.dao.cps.pojo.Ophost;
|
|
|
|
+import com.book.dao.cps.pojo.User;
|
|
|
|
+import com.book.server.common.entity.Result;
|
|
|
|
+import com.book.server.service.UserService;
|
|
|
|
+import com.book.server.service.WxPayService;
|
|
|
|
+import com.book.server.utils.DateUtil;
|
|
|
|
+import com.book.server.utils.HTTPSUtil;
|
|
|
|
+import com.book.server.utils.JsonUtils;
|
|
|
|
+import com.book.server.utils.Md5Util;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * created in 2021/8/30
|
|
|
|
+ * Project: book-store
|
|
|
|
+ *
|
|
|
|
+ * @author win7
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class WxPayServiceImpl implements WxPayService {
|
|
|
|
+
|
|
|
|
+ public static final String PALMPAY_APPID = "";
|
|
|
|
+ public static final String PALMPAY_APPKEY = "";
|
|
|
|
+ public static final String PALMPAY_MCHID = "";
|
|
|
|
+ public static final String PALMPAY_URL = "https://pay.palmpay.cn/sdkServer/thirdpays/pay/WECHAT_SUB";
|
|
|
|
+ @Autowired
|
|
|
|
+ private GoodsMapper goodsMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AdminConfigMapper adminConfigMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ConfigMapper configMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OphostMapper ophostMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public WxPayInfo createOrder(WxPayRequest wxPayRequest) {
|
|
|
|
+ Integer goodId = wxPayRequest.getGoodId();
|
|
|
|
+ Goods goods = goodsMapper.selectByPrimaryKey(goodId);
|
|
|
|
+ if (goods == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal money = goods.getMoney();
|
|
|
|
+ String amount = money.multiply(new BigDecimal(100)).toString();
|
|
|
|
+ //todo 支付域名
|
|
|
|
+ User userByUserId = userService.getUserByUserId(wxPayRequest.getUserId());
|
|
|
|
+ Integer channelId = userByUserId.getChannelId();
|
|
|
|
+ AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(channelId);
|
|
|
|
+ Integer ophostId = adminConfig.getOphostId();
|
|
|
|
+ Ophost ophost = ophostMapper.selectByPrimaryKey(ophostId);
|
|
|
|
+ Config url_pay = configMapper.selectByName("url_pay");
|
|
|
|
+ String url = url_pay.getValue();
|
|
|
|
+ //todo 入库
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ HashMap<String, String> map = new HashMap();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ long orderid = TimeUnit.NANOSECONDS.convert(System.currentTimeMillis(), TimeUnit.SECONDS) + wxPayRequest.getUserId();
|
|
|
|
+
|
|
|
|
+ map.put("appid", PALMPAY_APPID);
|
|
|
|
+ map.put("mchId", PALMPAY_MCHID);
|
|
|
|
+ map.put("version", "3.0");
|
|
|
|
+ map.put("charset", "UTF-8");
|
|
|
|
+ map.put("signType", "MD5");
|
|
|
|
+ map.put("productName", goods.getTitle());
|
|
|
|
+ map.put("productDesc", goods.getTitle());
|
|
|
|
+ map.put("outTradeNo", orderid + "");
|
|
|
|
+ map.put("money", amount);
|
|
|
|
+ map.put("callbackUrl", String.format("http://%s.%s/home.html#/center?userId=" + wxPayRequest.getUserId(), adminConfig.getAppid(), ophost.getHost()));
|
|
|
|
+ map.put("notifyUrl", url + "/api/wxpay/notify");
|
|
|
|
+ map.put("ip", wxPayRequest.getIp());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ map.put("subAppid", adminConfig.getAppid());
|
|
|
|
+ map.put("openid", userByUserId.getOpenid());
|
|
|
|
+ map.put("api", "1");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String str = PALMPAY_APPID + "WECHAT_SUB" + money + orderid + PALMPAY_APPKEY;
|
|
|
|
+
|
|
|
|
+ String sign = Md5Util.md5(str);
|
|
|
|
+ // sign = generalSign(map,md5key);
|
|
|
|
+ map.put("sign", sign);
|
|
|
|
+
|
|
|
|
+ String form = DateUtil.maptoform(map) + "";
|
|
|
|
+ System.out.println("请求:" + PALMPAY_URL + "?" + form);
|
|
|
|
+ String result = HTTPSUtil.sendGetByHttps(PALMPAY_URL, map);
|
|
|
|
+ System.out.println("响应:" + result);
|
|
|
|
+ PalmpayResponse object = JsonUtils.getObject(result, PalmpayResponse.class);
|
|
|
|
+ if (object == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (!"0".equals(object.getErrcode())) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ PalmpayResponse.Result r = object.getResult();
|
|
|
|
+ WxPayInfo wxPayInfo = new WxPayInfo();
|
|
|
|
+
|
|
|
|
+ r.getPay_info();
|
|
|
|
+ wxPayInfo.setPayInfo(r.getPay_info());
|
|
|
|
+ wxPayInfo.setOrderId(r.getOutTradeNo());
|
|
|
|
+ return wxPayInfo;
|
|
|
|
+ }
|
|
|
|
+}
|