提交代码

master
胡锐 4 months ago
parent ec13813c6d
commit b2aeefc5e8
  1. 55
      cweb/src/main/java/com/cweb/config/WxMsgConfig.java
  2. 57
      cweb/src/main/java/com/cweb/controller/BsUserController.java
  3. 10
      cweb/src/main/java/com/cweb/controller/order/OrderPayController.java
  4. 10
      service/src/main/java/com/hfkj/config/CommonSysConfig.java
  5. 15
      service/src/main/java/com/hfkj/config/WxMaConfiguration.java
  6. 6
      service/src/main/java/com/hfkj/pay/HuiPayService.java
  7. 3
      service/src/main/resources/dev/commonConfig.properties
  8. 4
      service/src/main/resources/prod/commonConfig.properties

@ -1,55 +0,0 @@
package com.cweb.config;
import cn.binarywang.wx.miniapp.api.WxMaMsgService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.hfkj.common.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class WxMsgConfig {
private static Logger log = LoggerFactory.getLogger(WxMsgConfig.class);
public static void pushOneUser(String orderName , String price , String orderNo , Date payTime , String remark , Long orderId , String openId) {
try {
List<WxMaSubscribeMessage.Data> list = new ArrayList<>();
Map<String, String> m = new HashMap<>();
m.put("thing1", orderName);
m.put("amount2", price + "元");
m.put("character_string3", orderNo);
m.put("time4", DateUtil.date2String(payTime , "yyyy年MM月dd日 HH:mm:ss"));
m.put("thing6", remark);
for (String key: m.keySet()) {
WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data();
msgElement.setName(key);
msgElement.setValue(m.get(key));
list.add(msgElement);
}
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage();
subscribeMessage.setToUser(openId); // 小程序openId
subscribeMessage.setTemplateId("oUvaCPeeOg4wH6HTvCcSabU6FnzXUXOBXsqBYAPOV-U");
subscribeMessage.setData(list);
subscribeMessage.setPage("pages/user/order_details/order_details?id=" + orderId);
subscribeMessage.setMiniprogramState("developer");
final WxMaService wxService = WxMaConfiguration.getMaService();
WxMaMsgService maMsgService = wxService.getMsgService();
maMsgService.sendSubscribeMsg(subscribeMessage);
} catch (Exception e) {
log.error(String.valueOf(e));
}
}
}

@ -1,5 +1,7 @@
package com.cweb.controller;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
@ -12,6 +14,7 @@ import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.common.utils.MemberValidateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.WxMaConfiguration;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.model.UserSessionObject;
@ -28,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
@ -113,6 +117,59 @@ public class BsUserController {
}
}
@RequestMapping(value = "/wxMaHandleCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "微信小程序code解析")
public ResponseData wxMaHandleCode(@RequestBody JSONObject body) {
try {
if (body == null|| StringUtils.isBlank(body.getString("code"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
//请求微信api,获取用户session_key以及openId
WxMaJscode2SessionResult session = WxMaConfiguration.getMaService().jsCode2SessionInfo(body.getString("code"));
//保存小程序用户登录的openId及sessionKey信息
redisUtil.hset("WX_OPENID_SESSION_REDIS", session.getOpenid(), session);
JSONObject jo = new JSONObject();
jo.put("openId", session.getOpenid());
return ResponseMsgUtil.success(jo);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/wxMaLogin", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "微信小程序手机号的登录")
public ResponseData wxMaLogin(@RequestBody JSONObject body) {
try {
if (body == null
|| StringUtils.isBlank(body.getString("encryptedData"))
|| StringUtils.isBlank(body.getString("iv"))
|| StringUtils.isBlank(body.getString("openId"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
String encryptedData = body.getString("encryptedData").replace(" ", "+");
String iv = body.getString("iv").replace(" ", "+");
//请求微信api,获取用户session_key以及openId
Object skObject = redisUtil.hget("WX_OPENID_SESSION_REDIS", body.getString("openId"));
if (skObject == null) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR);
}
WxMaJscode2SessionResult session = (WxMaJscode2SessionResult) skObject;
WxMaPhoneNumberInfo phoneNoInfo = WxMaConfiguration.getMaService().getUserService().getPhoneNoInfo(session.getSessionKey(), encryptedData, iv);
if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) {
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "登录失败! 用户手机号解析失败");
}
Map<String, Object> other = new HashMap<>();
return ResponseMsgUtil.success(userService.login(UserLoginPlatform.H5, UserLoginType.WECHAT_MA_PHONE, phoneNoInfo.getPhoneNumber(), other));
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/queryUser", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "查询用户信息")

@ -7,6 +7,7 @@ import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.RandomUtils;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.CommonSysConst;
import com.hfkj.entity.BsGasChannelConfig;
import com.hfkj.entity.BsMerchant;
import com.hfkj.entity.BsMerchantPayConfig;
@ -111,8 +112,13 @@ public class OrderPayController {
ledgerAccountFlag = payConfig.getLedgerAccountFlag();
}
order.setPayType(OrderPayTypeEnum.type1.getCode());
// appIdType 1: 公众号 2:小程序
if (body.getInteger("appIdType") != null && body.getInteger("appIdType") == 2) {
body.put("appId", CommonSysConst.getSysConfig().getWxMaAppId());
}
// 请求支付渠道
Map<Object, Object> preorder = HuiPayService.preorder(payMerNo, payMerKey, body.getString("openId"), ledgerAccountFlag, order);
Map<Object, Object> preorder = HuiPayService.preorder(payMerNo, payMerKey, body.getString("appId"), body.getString("openId"), ledgerAccountFlag, order);
// 交易入账
BsOrderSettle orderSettle = orderSettleService.getData(order.getOrderNo());
if (orderSettle == null) {
@ -166,7 +172,7 @@ public class OrderPayController {
}
order.setPayType(OrderPayTypeEnum.type2.getCode());
// 请求支付渠道
Map<Object, Object> preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), body.getString("userId"), merPay.getLedgerAccountFlag(), order);
Map<Object, Object> preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), null, body.getString("userId"), merPay.getLedgerAccountFlag(), order);
// 交易入账
BsOrderSettle orderSettle = orderSettleService.getData(order.getOrderNo());

@ -14,6 +14,16 @@ public class CommonSysConfig {
* 文件存放地址 可访问
*/
private String filesystem;
/**
* 微信小程序APPID
*/
private String wxMaAppId;
/**
* 微信小程序Secret
*/
private String wxMaAppSecret;
/**
* 能链团油请求地址
*/

@ -1,4 +1,4 @@
package com.cweb.config;
package com.hfkj.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
@ -14,20 +14,17 @@ public class WxMaConfiguration {
public static WxMaService getMaService() {
if (maService == null) {
throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!"));
throw new IllegalArgumentException(String.format("未找到对应的小程序配置,请核实!"));
}
return maService;
}
@PostConstruct
public void init() {
/*WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(SysConst.getSysConfig().getWxAppId());
config.setSecret(SysConst.getSysConfig().getWxAppSecret());
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(CommonSysConst.getSysConfig().getWxMaAppId());
config.setSecret(CommonSysConst.getSysConfig().getWxMaAppSecret());
maService = new WxMaServiceImpl();
maService.setWxMaConfig(config);*/
maService.setWxMaConfig(config);
}
}

@ -14,6 +14,7 @@ import com.hfkj.entity.BsOrderSettle;
import com.hfkj.entity.BsOrderSettleLedger;
import com.hfkj.model.order.OrderModel;
import com.hfkj.sysenum.order.OrderPayTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -37,7 +38,7 @@ public class HuiPayService {
* @return
* @throws Exception
*/
public static Map<Object, Object> preorder(String merNo,String merKey,String openId,boolean profitSharing,OrderModel order) throws Exception {
public static Map<Object, Object> preorder(String merNo,String merKey,String appId,String openId,boolean profitSharing,OrderModel order) throws Exception {
try {
log.info("=============== start 惠支付 start ==================");
Map<String, Object> param = new HashMap<>();
@ -51,6 +52,9 @@ public class HuiPayService {
}
param.put("totalAmount", order.getPayRealPrice());
param.put("profitSharing", profitSharing?1:0);
if (StringUtils.isNotBlank(appId)) {
param.put("subAppid", appId);
}
param.put("subject", "在线加油");
param.put("userId", openId);
param.put("notifyUrl", CommonSysConst.getSysConfig().getHuiPayPreorderNotifyUrl());

@ -1,6 +1,9 @@
filesystem=/home/project/oil/filesystem
huiPayPreorderNotifyUrl=https://test-oil.dctpay.com/crest/notify/huipay
domainName=https://test-oil.dctpay.com
wxMaAppId=wx8d49e2f83025229d
wxMaAppSecret=d8d6dcaef77d3b659258a01b5ddba5df
# newLinkReqUrl=https://hcs.czb365.com
# newLinkAppKey=305490138943968
# newLinkAppSecret=dbf7dca3de20c2f2a41fd64cfb682be8

@ -1,6 +1,10 @@
filesystem=/home/project/oil/filesystem
huiPayPreorderNotifyUrl=https://oil.dctpay.com/crest/notify/huipay
domainName=https://oil.dctpay.com
wxMaAppId=wx8d49e2f83025229d
wxMaAppSecret=d8d6dcaef77d3b659258a01b5ddba5df
newLinkReqUrl=https://hcs.czb365.com
newLinkAppKey=305490138943968
newLinkAppSecret=dbf7dca3de20c2f2a41fd64cfb682be8

Loading…
Cancel
Save