|
|
@@ -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);
|