|
@@ -2,8 +2,10 @@ package com.izouma.weixin.web;
|
|
|
|
|
|
|
|
import com.izouma.awesomeadmin.constant.AppConstant;
|
|
import com.izouma.awesomeadmin.constant.AppConstant;
|
|
|
import com.izouma.awesomeadmin.model.MemberCoin;
|
|
import com.izouma.awesomeadmin.model.MemberCoin;
|
|
|
|
|
+import com.izouma.awesomeadmin.model.ProductInfo;
|
|
|
import com.izouma.awesomeadmin.model.UserInfo;
|
|
import com.izouma.awesomeadmin.model.UserInfo;
|
|
|
import com.izouma.awesomeadmin.service.MemberCoinService;
|
|
import com.izouma.awesomeadmin.service.MemberCoinService;
|
|
|
|
|
+import com.izouma.awesomeadmin.service.ProductInfoService;
|
|
|
import com.izouma.awesomeadmin.service.UserInfoService;
|
|
import com.izouma.awesomeadmin.service.UserInfoService;
|
|
|
import com.izouma.awesomeadmin.shiro.WechatToken;
|
|
import com.izouma.awesomeadmin.shiro.WechatToken;
|
|
|
import com.izouma.awesomeadmin.util.Base64;
|
|
import com.izouma.awesomeadmin.util.Base64;
|
|
@@ -56,6 +58,9 @@ public class WeiXinController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WxpayTempMapper wxpayTempMapper;
|
|
private WxpayTempMapper wxpayTempMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
|
|
+
|
|
|
@RequestMapping(value = "/auth", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/auth", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public ModelAndView auth(@RequestParam("redirectUri") String redirectUri) {
|
|
public ModelAndView auth(@RequestParam("redirectUri") String redirectUri) {
|
|
@@ -115,153 +120,67 @@ public class WeiXinController {
|
|
|
JSONObject attachJson = new JSONObject(attach);
|
|
JSONObject attachJson = new JSONObject(attach);
|
|
|
|
|
|
|
|
WxpayTemp wxpayTemp = new WxpayTemp();
|
|
WxpayTemp wxpayTemp = new WxpayTemp();
|
|
|
- wxpayTemp.setOrderId(attachJson.getString("orderId"));
|
|
|
|
|
- wxpayTemp.setCoin(BigDecimal.valueOf(attachJson.getDouble("coin")));
|
|
|
|
|
- wxpayTemp.setPoint(BigDecimal.valueOf(attachJson.getDouble("point")));
|
|
|
|
|
|
|
+ wxpayTemp.setUserId(attachJson.getString("userId"));
|
|
|
|
|
+ wxpayTemp.setOrderId(attachJson.getString("productId"));
|
|
|
wxpayTemp.setCash(BigDecimal.valueOf(attachJson.getDouble("cash")));
|
|
wxpayTemp.setCash(BigDecimal.valueOf(attachJson.getDouble("cash")));
|
|
|
wxpayTemp.setTotalAmount(BigDecimal.valueOf(attachJson.getInt("total") / 100.0));
|
|
wxpayTemp.setTotalAmount(BigDecimal.valueOf(attachJson.getInt("total") / 100.0));
|
|
|
wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
|
|
wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
|
|
|
wxpayTemp.setTransactionId(m.get("transaction_id"));
|
|
wxpayTemp.setTransactionId(m.get("transaction_id"));
|
|
|
- wxpayTemp.setTypeFlag(AppConstant.Aliapi.BUY);
|
|
|
|
|
-
|
|
|
|
|
- wxpayTempMapper.insertSelective(wxpayTemp);
|
|
|
|
|
-
|
|
|
|
|
- //TODO 订单回调
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- logger.error("微信支付回调异常", e);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @RequestMapping(value = "/notifyRecharge", method = RequestMethod.POST)
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public ModelAndView notifyRecharge(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- Map<String, String> m = notifyMap(request, response);
|
|
|
|
|
- if (m != null && "SUCCESS".equals(m.get("result_code"))) {
|
|
|
|
|
- String attach = m.get("attach");
|
|
|
|
|
- JSONObject attachJson = new JSONObject(attach);
|
|
|
|
|
|
|
|
|
|
- Integer userId = attachJson.getInt("userId");
|
|
|
|
|
- Integer money = attachJson.getInt("money") / 100;
|
|
|
|
|
|
|
+ wxpayTempMapper.updateByOutTradeNo(wxpayTemp);
|
|
|
|
|
|
|
|
- UserInfo userInfo = userInfoService.getUserInfoById(userId + "");
|
|
|
|
|
|
|
+ logger.info("buyProductInfo");
|
|
|
|
|
+ try {
|
|
|
|
|
+ ProductInfo productInfo = productInfoService.getProductInfoById(attachJson.getString("productId"));
|
|
|
|
|
+ if (productInfo != null) {
|
|
|
|
|
+ if (AppConstant.ProductType.RECHARGE == productInfo.getTypeFlag()) {//如果是充值类型
|
|
|
|
|
|
|
|
|
|
+ MemberCoin memberCoin = new MemberCoin();
|
|
|
|
|
+ memberCoin.setMoney(productInfo.getCoin());
|
|
|
|
|
+ memberCoin.setUserId(Integer.valueOf(attachJson.getString("userId")));
|
|
|
|
|
+ memberCoin.setRemark("购买" + productInfo.getProductName() + "套餐,充值");
|
|
|
|
|
+ memberCoin.setRechargeType(AppConstant.RechargeType.WEI_XIN);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 余额
|
|
|
|
|
- */
|
|
|
|
|
- double moneyCoin = userInfo.getMoneyCoin();
|
|
|
|
|
- UserInfo updateUser = new UserInfo();
|
|
|
|
|
- updateUser.setId(userId);
|
|
|
|
|
- updateUser.setMoneyCoin(moneyCoin + money);
|
|
|
|
|
- userInfoService.updateUserInfo(updateUser);
|
|
|
|
|
|
|
+ memberCoinService.recharge(memberCoin);
|
|
|
|
|
|
|
|
|
|
|
|
|
- MemberCoin memberCoin = new MemberCoin();
|
|
|
|
|
- memberCoin.setCreateUser("微信充值");
|
|
|
|
|
- memberCoin.setUserId(userId);
|
|
|
|
|
- memberCoin.setMoney(BigDecimal.valueOf(money));
|
|
|
|
|
- memberCoin.setBalance(BigDecimal.valueOf(moneyCoin + money));
|
|
|
|
|
- memberCoin.setTypeFlag(AppConstant.CoinType.RECHARGE);
|
|
|
|
|
- memberCoin.setRemark("微信充值," + money);
|
|
|
|
|
- memberCoinService.createMemberCoin(memberCoin);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //TODO 购买VIP
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- WxpayTemp wxpayTemp = new WxpayTemp();
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("buyProductInfo", e);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- wxpayTemp.setUserId(String.valueOf(userId));
|
|
|
|
|
- wxpayTemp.setOutTradeNo(m.get("out_trade_no"));
|
|
|
|
|
- wxpayTemp.setTransactionId(m.get("transaction_id"));
|
|
|
|
|
- wxpayTemp.setTotalAmount(BigDecimal.valueOf(money));
|
|
|
|
|
- wxpayTemp.setTypeFlag(AppConstant.Aliapi.RECHARGE);
|
|
|
|
|
|
|
|
|
|
- wxpayTempMapper.insertSelective(wxpayTemp);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.error("微信充值回调异常", e);
|
|
|
|
|
|
|
+ logger.error("微信支付回调异常", e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- @RequestMapping(value = "/recharge", method = RequestMethod.POST)
|
|
|
|
|
|
|
+ @RequestMapping(value = "/unifiedOrder", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public Map recharge(@RequestParam(required = true, value = "userId") Integer userId, @RequestParam(required = true, value = "money") Integer money) {
|
|
|
|
|
- Map<String, String> result = new HashMap<String, String>();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public Map<String, String> unifiedOrder(@RequestParam(required = true, value = "userId") String userId,
|
|
|
|
|
+ @RequestParam(required = true, value = "productId") String productId
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
MyConfig config = new MyConfig();
|
|
MyConfig config = new MyConfig();
|
|
|
|
|
|
|
|
- int total = money;
|
|
|
|
|
-
|
|
|
|
|
- //测试为一分
|
|
|
|
|
- //total = 1;
|
|
|
|
|
-
|
|
|
|
|
- JSONObject attach = new JSONObject();
|
|
|
|
|
- attach.put("userId", userId);
|
|
|
|
|
- attach.put("money", money);
|
|
|
|
|
-
|
|
|
|
|
- WxPaySendData data = new WxPaySendData();
|
|
|
|
|
- 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"));
|
|
|
|
|
- data.setTotal_fee(total);
|
|
|
|
|
- data.setTrade_type(AppConstant.TRADE_TYPE_APP);
|
|
|
|
|
- //data.setSpbill_create_ip("117.62.182.63");
|
|
|
|
|
- data.setSpbill_create_ip(WeixinUtil.getHostAdderss());
|
|
|
|
|
- //扫码支付不需要openId
|
|
|
|
|
- //data.setOpenid(openId);
|
|
|
|
|
-
|
|
|
|
|
- data.setAttach(attach.toString());
|
|
|
|
|
-
|
|
|
|
|
- Map<String, String> unified = WeixinUtil.unifiedOrder(data);
|
|
|
|
|
-
|
|
|
|
|
- String timeStamp = MbappUtil.create_timestamp();
|
|
|
|
|
- String nonceStr = MbappUtil.create_nonce_str();
|
|
|
|
|
- String packageStr = "prepay_id=" + unified.get("prepay_id");
|
|
|
|
|
- //生成sign签名
|
|
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
|
|
-
|
|
|
|
|
- params.put("appId", config.getAppID());
|
|
|
|
|
- params.put("timeStamp", timeStamp);
|
|
|
|
|
- params.put("nonceStr", nonceStr);
|
|
|
|
|
- params.put("package", packageStr);
|
|
|
|
|
-
|
|
|
|
|
- result.put("appId", config.getAppID());
|
|
|
|
|
- result.put("timeStamp", timeStamp);
|
|
|
|
|
- result.put("nonceStr", nonceStr);
|
|
|
|
|
- result.put("myPackage", packageStr);
|
|
|
|
|
- result.put("paySign", WXPayUtil.generateSignature(params, config.getKey()));
|
|
|
|
|
-
|
|
|
|
|
- result.put("prepay_id", unified.get("prepay_id"));
|
|
|
|
|
- result.put("code_url", unified.get("code_url"));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- logger.error("", e);
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ double cash = 1;
|
|
|
|
|
|
|
|
- @RequestMapping(value = "/unifiedOrder", method = RequestMethod.GET)
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public Map<String, String> unifiedOrder(@RequestParam(required = true, value = "orderId") String orderId, @RequestParam(required = true, value = "coin") double coin,
|
|
|
|
|
- @RequestParam(required = true, value = "point") double point) {
|
|
|
|
|
- Map<String, String> result = new HashMap<>();
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ ProductInfo productInfo = productInfoService.getProductInfoById(productId);
|
|
|
|
|
|
|
|
- MyConfig config = new MyConfig();
|
|
|
|
|
|
|
+ cash = productInfo.getMoney().doubleValue();
|
|
|
|
|
|
|
|
- double cash = 1;//userOrderService.calculatedPrice(orderId, coin, point);
|
|
|
|
|
int total = 0;
|
|
int total = 0;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -271,15 +190,14 @@ public class WeiXinController {
|
|
|
//total = 1;
|
|
//total = 1;
|
|
|
|
|
|
|
|
JSONObject attach = new JSONObject();
|
|
JSONObject attach = new JSONObject();
|
|
|
- attach.put("orderId", orderId);
|
|
|
|
|
- attach.put("coin", coin);
|
|
|
|
|
- attach.put("point", point);
|
|
|
|
|
|
|
+ attach.put("productId", productId);
|
|
|
|
|
+ attach.put("userId", userId);
|
|
|
attach.put("cash", cash);
|
|
attach.put("cash", cash);
|
|
|
attach.put("total", total);
|
|
attach.put("total", total);
|
|
|
|
|
|
|
|
WxPaySendData data = new WxPaySendData();
|
|
WxPaySendData data = new WxPaySendData();
|
|
|
data.setDevice_info(AppConstant.DEVICE_INFO);
|
|
data.setDevice_info(AppConstant.DEVICE_INFO);
|
|
|
- data.setBody("商品");
|
|
|
|
|
|
|
+ data.setBody(productInfo.getProductName());
|
|
|
data.setOut_trade_no(MbappUtil.create_out_trade_no());
|
|
data.setOut_trade_no(MbappUtil.create_out_trade_no());
|
|
|
data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url"));
|
|
data.setNotify_url(PropertiesFileLoader.getProperties("weixin_notify_url"));
|
|
|
data.setTotal_fee(total);
|
|
data.setTotal_fee(total);
|
|
@@ -310,6 +228,17 @@ public class WeiXinController {
|
|
|
|
|
|
|
|
result.put("prepay_id", unified.get("prepay_id"));
|
|
result.put("prepay_id", unified.get("prepay_id"));
|
|
|
result.put("code_url", unified.get("code_url"));
|
|
result.put("code_url", unified.get("code_url"));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ WxpayTemp wxpayTemp = new WxpayTemp();
|
|
|
|
|
+ wxpayTemp.setOrderId(productId);
|
|
|
|
|
+ wxpayTemp.setCash(BigDecimal.valueOf(cash));
|
|
|
|
|
+ wxpayTemp.setTotalAmount(BigDecimal.valueOf(total / 100.0));
|
|
|
|
|
+ wxpayTemp.setOutTradeNo(data.getOut_trade_no());
|
|
|
|
|
+ wxpayTemp.setTypeFlag(AppConstant.Aliapi.BUY);
|
|
|
|
|
+ wxpayTemp.setResultCode("WAIT_BUYER_PAY");
|
|
|
|
|
+ wxpayTempMapper.insertSelective(wxpayTemp);
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
logger.error("", e);
|
|
logger.error("", e);
|
|
|
}
|
|
}
|