suochencheng 6 жил өмнө
parent
commit
f1f34f3f00

+ 0 - 1
src/main/java/com/izouma/awesomeadmin/service/impl/UserInfoServiceImpl.java

@@ -6,7 +6,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
 import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
 import com.izouma.awesomeadmin.constant.AppConstant;
-import com.izouma.awesomeadmin.container.WeixinConfig;
 import com.izouma.awesomeadmin.dao.*;
 import com.izouma.awesomeadmin.dto.Page;
 import com.izouma.awesomeadmin.dto.Result;

+ 1 - 2
src/main/java/com/izouma/weixin/util/WeixinUtil.java

@@ -37,7 +37,7 @@ public class WeixinUtil {
      * @param data
      * @return
      */
-    public static Map<String, String> unifiedOrder(WxPaySendData data) {
+    public static Map<String, String> unifiedOrder(WxPaySendData data, MyConfig config) {
 
         Map<String, String> map = new HashMap<String, String>();
         try {
@@ -56,7 +56,6 @@ public class WeixinUtil {
             parameters.put("attach", data.getAttach());
 
 
-            MyConfig config = new MyConfig();
             WXPay wxpay = new WXPay(config);
 
             map = wxpay.unifiedOrder(parameters);

+ 51 - 17
src/main/java/com/izouma/weixin/web/WeiXinController.java

@@ -1,8 +1,10 @@
 package com.izouma.weixin.web;
 
 import com.izouma.awesomeadmin.constant.AppConstant;
+import com.izouma.awesomeadmin.dao.WxMiniprogramMapper;
 import com.izouma.awesomeadmin.model.MemberCoin;
 import com.izouma.awesomeadmin.model.UserInfo;
+import com.izouma.awesomeadmin.model.WxMiniprogram;
 import com.izouma.awesomeadmin.service.MemberCoinService;
 import com.izouma.awesomeadmin.service.UserInfoService;
 import com.izouma.awesomeadmin.service.UserOrderService;
@@ -61,6 +63,9 @@ public class WeiXinController {
     @Autowired
     private WxpayTempMapper wxpayTempMapper;
 
+    @Autowired
+    private WxMiniprogramMapper wxMiniprogramMapper;
+
     @RequestMapping(value = "/auth", method = RequestMethod.GET)
     @ResponseBody
     public ModelAndView auth(@RequestParam("redirectUri") String redirectUri) {
@@ -109,12 +114,12 @@ public class WeiXinController {
     }
 
 
-    @RequestMapping(value = "/notify", method = RequestMethod.POST)
+    @RequestMapping(value = "/notify/{miniId}", method = RequestMethod.POST)
     @ResponseBody
-    public ModelAndView notify(HttpServletRequest request, HttpServletResponse response) {
+    public ModelAndView notify(@PathVariable Integer miniId, HttpServletRequest request, HttpServletResponse response) {
 
         try {
-            Map<String, String> m = notifyMap(request, response);
+            Map<String, String> m = notifyMap(request, response, miniId);
             if (m != null && "SUCCESS".equals(m.get("result_code"))) {
                 String attach = m.get("attach");
                 JSONObject attachJson = new JSONObject(attach);
@@ -143,13 +148,13 @@ public class WeiXinController {
     }
 
 
-    @RequestMapping(value = "/notifyRecharge", method = RequestMethod.POST)
+    @RequestMapping(value = "/notifyRecharge/{miniId}", method = RequestMethod.POST)
     @ResponseBody
-    public ModelAndView notifyRecharge(HttpServletRequest request, HttpServletResponse response) {
+    public ModelAndView notifyRecharge(@PathVariable Integer miniId, HttpServletRequest request, HttpServletResponse response) {
 
         try {
 
-            Map<String, String> m = notifyMap(request, response);
+            Map<String, String> m = notifyMap(request, response, miniId);
             if (m != null && "SUCCESS".equals(m.get("result_code"))) {
                 String attach = m.get("attach");
                 JSONObject attachJson = new JSONObject(attach);
@@ -203,7 +208,8 @@ public class WeiXinController {
     @ResponseBody
     public Map recharge(@RequestParam(required = true, value = "openId") String openId,
                         @RequestParam(required = true, value = "userId") Integer userId,
-                        @RequestParam(required = true, value = "money") Integer money) {
+                        @RequestParam(required = true, value = "money") Integer money,
+                        @RequestParam(required = true, value = "miniId") Integer miniId) {
         Map<String, String> result = new HashMap<String, String>();
 
         try {
@@ -213,7 +219,7 @@ public class WeiXinController {
             String ip = WeixinUtil.getIpAdderss(request);
 
 
-            MyConfig config = new MyConfig();
+            MyConfig config = getMyConfig(miniId);
 
             int total = money;
 
@@ -228,7 +234,8 @@ public class WeiXinController {
             data.setDevice_info(AppConstant.DEVICE_INFO);
             data.setBody("充值");
             data.setOut_trade_no(WeixinUtil.create_out_trade_no());
-            data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url_recharge"));
+            String notify_url = PropertiesFileLoader.getProperties("weixin_notify_url_recharge") + "/" + miniId;
+            data.setNotify_url(notify_url);
             data.setTotal_fee(total);
             data.setTrade_type(AppConstant.TRADE_TYPE_JSAPI);
             //data.setSpbill_create_ip("117.62.182.63");
@@ -238,7 +245,7 @@ public class WeiXinController {
             data.setAttach(attach.toString());
 
 
-            Map<String, String> unified = WeixinUtil.unifiedOrder(data);
+            Map<String, String> unified = WeixinUtil.unifiedOrder(data, config);
 
             String timeStamp = WeixinUtil.create_timestamp();
             String nonceStr = WeixinUtil.create_nonce_str();
@@ -266,12 +273,38 @@ public class WeiXinController {
         return result;
     }
 
+    private MyConfig getMyConfig(@RequestParam(required = true, value = "miniId") Integer miniId) throws Exception {
+        MyConfig config = new MyConfig();
+
+        config.setAppID(PropertiesFileLoader.getProperties("weixinappid"));
+        config.setMchID(PropertiesFileLoader.getProperties("weixin_mch_id"));
+        config.setKey(PropertiesFileLoader.getProperties("weixin_mch_secret"));
+
+        if (miniId != null) {
+
+            WxMiniprogram wxMiniprogram = new WxMiniprogram();
+            wxMiniprogram.setUseFlag("Y");
+            wxMiniprogram.setId(miniId);
+
+            wxMiniprogram = wxMiniprogramMapper.selectByPrimaryKey(miniId);
+
+            if (wxMiniprogram != null) {
+                config.setAppID(wxMiniprogram.getAppid());
+                config.setMchID(wxMiniprogram.getMchId());
+                config.setKey(wxMiniprogram.getMchSecret());
+            }
+
+        }
+        return config;
+    }
+
     @RequestMapping(value = "/unifiedOrder", method = RequestMethod.GET)
     @ResponseBody
     public Map<String, String> unifiedOrder(@RequestParam(required = true, value = "openId") String openId,
                                             @RequestParam(required = true, value = "orderId") String orderId,
                                             @RequestParam(required = true, value = "coin") double coin,
-                                            @RequestParam(required = true, value = "point") double point) {
+                                            @RequestParam(required = true, value = "point") double point,
+                                            @RequestParam(required = true, value = "miniId") Integer miniId) {
         Map<String, String> result = new HashMap<>();
         try {
 
@@ -279,7 +312,7 @@ public class WeiXinController {
 
             String ip = WeixinUtil.getIpAdderss(request);
 
-            MyConfig config = new MyConfig();
+            MyConfig config = getMyConfig(miniId);
 
             double cash = userOrderService.calculatedPrice(orderId, coin, point);
             int total = 0;
@@ -288,7 +321,7 @@ public class WeiXinController {
             total = (int) (cash * 100);
 
             //测试为一分
-            //total = 1;
+            total = 1;
 
             JSONObject attach = new JSONObject();
             attach.put("orderId", orderId);
@@ -305,7 +338,8 @@ public class WeiXinController {
             data.setDevice_info(AppConstant.DEVICE_INFO);
             data.setBody("小程序商品");
             data.setOut_trade_no(WeixinUtil.create_out_trade_no());
-            data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url"));
+            String notify_url = PropertiesFileLoader.getProperties("weixin_notify_url") + "/" + miniId;
+            data.setNotify_url(notify_url);
             data.setTotal_fee(total);
             data.setTrade_type(AppConstant.TRADE_TYPE_JSAPI);
             //data.setSpbill_create_ip("117.62.182.63");
@@ -314,7 +348,7 @@ public class WeiXinController {
             data.setAttach(attach.toString());
 
 
-            Map<String, String> unified = WeixinUtil.unifiedOrder(data);
+            Map<String, String> unified = WeixinUtil.unifiedOrder(data, config);
 
             String timeStamp = WeixinUtil.create_timestamp();
             String nonceStr = WeixinUtil.create_nonce_str();
@@ -355,7 +389,7 @@ public class WeiXinController {
      * @param response
      * @return
      */
-    public Map<String, String> notifyMap(HttpServletRequest request, HttpServletResponse response) {
+    public Map<String, String> notifyMap(HttpServletRequest request, HttpServletResponse response, Integer miniId) {
 
         logger.info("payOrder:支付订单");
         Map<String, String> notifyMap = new HashMap<>();
@@ -377,7 +411,7 @@ public class WeiXinController {
 
             System.out.println("接收到的报文:" + notityXml);
 
-            MyConfig config = new MyConfig();
+            MyConfig config = getMyConfig(miniId);
             WXPay wxpay = new WXPay(config);
 
             notifyMap = WXPayUtil.xmlToMap(notityXml);

+ 21 - 3
src/main/java/com/izouma/weixin/wxpay/MyConfig.java

@@ -12,6 +12,12 @@ public class MyConfig extends WXPayConfig implements IWXPayDomain {
 
     private byte[] certData;
 
+    private String appID;
+
+    private String mchID;
+
+    private String key;
+
     public MyConfig() throws Exception {
         //String certPath = "/path/to/apiclient_cert.p12";
         String certPath = PropertiesFileLoader.getProperties("weixin_cert_path");
@@ -23,15 +29,15 @@ public class MyConfig extends WXPayConfig implements IWXPayDomain {
     }
 
     public String getAppID() {
-        return PropertiesFileLoader.getProperties("weixinappid");
+        return this.appID;
     }
 
     public String getMchID() {
-        return PropertiesFileLoader.getProperties("weixin_mch_id");
+        return this.mchID;
     }
 
     public String getKey() {
-        return PropertiesFileLoader.getProperties("weixin_mch_secret");
+        return this.key;
     }
 
     public InputStream getCertStream() {
@@ -61,5 +67,17 @@ public class MyConfig extends WXPayConfig implements IWXPayDomain {
     public DomainInfo getDomain(WXPayConfig config) {
         return new DomainInfo(WXPayConstants.DOMAIN_API, true);
     }
+
+    public void setAppID(String appID) {
+        this.appID = appID;
+    }
+
+    public void setMchID(String mchID) {
+        this.mchID = mchID;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
 }
 

+ 3 - 3
src/main/resources/properties/outsidews.properties

@@ -19,9 +19,9 @@ ALIPAY_ALIPAY_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApFWFg9xMrqj
 ALIPAY_SIGN_TYPE=RSA2
 ALIPAY_SELLER=2088331233110526
 ALIPAY_GATEWAY=https://openapi.alipay.com/gateway.do
-weixin_mch_id=1533580721
-weixin_mch_secret=liuhuohuyu6666666666688888888888
-weixin_notify_url=http://www.liuhuohuyu.com/wx/notify
+weixin_mch_id=1326510801
+weixin_mch_secret=aa1b1d19893e48dc6c3c76weiqiuwang
+weixin_notify_url=https://xcx.izouma.com/wx/notify
 weixin_cert_path=/home/cert/apiclient_cert.p12
 weixin_notify_url_recharge=