添加支付宝以及微信公众号配置参数
This commit is contained in:
@@ -37,9 +37,9 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
public String getOpenId(String code, String source) {
|
||||
String openId;
|
||||
if (UserAuthSourceEnum.WECHAT.getValue().equals(source)) {
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(code);
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(code, true);
|
||||
}else {
|
||||
openId = alipayUtil.getOpenId(code);
|
||||
openId = alipayUtil.getOpenId(code, true);
|
||||
}
|
||||
return openId;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
UserInfo userInfo;
|
||||
String openId;
|
||||
if (UserAuthSourceEnum.WECHAT.getValue().equals(userAuthorizationLoginDTO.getSource())) {
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(userAuthorizationLoginDTO.getCode());
|
||||
openId = wechatAuthUtil.getSessionKeyOrOpenId(userAuthorizationLoginDTO.getCode(), false);
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getWechatOpenId, openId).one();
|
||||
userInfo = userInfo == null ? new UserInfo() : userInfo;
|
||||
if (StrUtil.isNotBlank(userAuthorizationLoginDTO.getRawData())) {
|
||||
@@ -62,7 +62,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
||||
}
|
||||
userInfo.setWechatOpenId(openId);
|
||||
} else {
|
||||
openId = alipayUtil.getOpenId(userAuthorizationLoginDTO.getCode());
|
||||
openId = alipayUtil.getOpenId(userAuthorizationLoginDTO.getCode(), false);
|
||||
userInfo = userInfoService.queryChain().eq(UserInfo::getAlipayOpenId, openId).one();
|
||||
userInfo = userInfo == null ? new UserInfo() : userInfo;
|
||||
userInfo.setNickName("支付宝用户");
|
||||
|
||||
@@ -32,6 +32,7 @@ public class AlipayUtil {
|
||||
*/
|
||||
@Value("${alipay.appId}")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 应用私钥
|
||||
*/
|
||||
@@ -48,30 +49,38 @@ public class AlipayUtil {
|
||||
@Value("${alipay.encryptKey}")
|
||||
private String encryptKey;
|
||||
|
||||
@Value("${alipay.account.appId}")
|
||||
private String accountAppId;
|
||||
@Value("${alipay.account.privateKey}")
|
||||
private String accountPrivateKey;
|
||||
@Value("${alipay.account.publicKey}")
|
||||
private String accountPublicKey;
|
||||
|
||||
/**
|
||||
* 创建支付宝客户端
|
||||
* @return AlipayClient
|
||||
*/
|
||||
@SneakyThrows
|
||||
public AlipayClient createClient() {
|
||||
public AlipayClient createClient(boolean isAccount) {
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
//设置网关地址
|
||||
alipayConfig.setServerUrl(serverUrl);
|
||||
//设置应用ID
|
||||
alipayConfig.setAppId(appId);
|
||||
alipayConfig.setAppId(isAccount ? accountAppId : appId);
|
||||
//设置应用私钥
|
||||
alipayConfig.setPrivateKey(privateKey);
|
||||
alipayConfig.setPrivateKey(isAccount ? accountPrivateKey : privateKey);
|
||||
//设置支付宝公钥
|
||||
alipayConfig.setAlipayPublicKey(alipayPublicKey);
|
||||
alipayConfig.setAlipayPublicKey(isAccount ? accountPublicKey : alipayPublicKey);
|
||||
return new DefaultAlipayClient(alipayConfig);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取支付宝用户的openId
|
||||
* @param code 用户信息授权码
|
||||
* @return openId
|
||||
*/
|
||||
public String getOpenId(String code){
|
||||
public String getOpenId(String code, boolean isAccount){
|
||||
AlipaySystemOauthTokenRequest req = new AlipaySystemOauthTokenRequest();
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数
|
||||
req.setCode(code);
|
||||
@@ -80,7 +89,7 @@ public class AlipayUtil {
|
||||
//req.setBizContent(" {" + " \"primary_industry_name\":\"IT科技/IT软件与服务\"," + " \"primary_industry_code\":\"10001/20102\"," + " \"secondary_industry_code\":\"10001/20102\"," + " \"secondary_industry_name\":\"IT科技/IT软件与服务\"" + " }");
|
||||
AlipaySystemOauthTokenResponse response;
|
||||
try {
|
||||
response = createClient().execute(req);
|
||||
response = createClient(isAccount).execute(req);
|
||||
}catch (Exception e){
|
||||
log.error("获取支付宝用户信息失败", e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -21,10 +21,16 @@ public class WechatAuthUtil {
|
||||
|
||||
@Value("${wx.appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${wx.secrete}")
|
||||
private String secrete;
|
||||
|
||||
@Value("${wx.account.appId}")
|
||||
private String accountAppId;
|
||||
@Value("${wx.account.secrete}")
|
||||
private String accountSecrete;
|
||||
|
||||
|
||||
|
||||
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
@@ -41,14 +47,14 @@ public class WechatAuthUtil {
|
||||
|
||||
}
|
||||
|
||||
public String getSessionKeyOrOpenId(String code) {
|
||||
public String getSessionKeyOrOpenId(String code, boolean isAccount) {
|
||||
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
Map<String, Object> requestUrlParam = new HashMap<>();
|
||||
// https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
|
||||
//小程序appId
|
||||
requestUrlParam.put("appid", appId);
|
||||
requestUrlParam.put("appid", isAccount ? accountAppId : appId);
|
||||
//小程序secret
|
||||
requestUrlParam.put("secret", secrete);
|
||||
requestUrlParam.put("secret", isAccount ? accountSecrete : secrete);
|
||||
//小程序端返回的code
|
||||
requestUrlParam.put("js_code", code);
|
||||
//默认参数
|
||||
|
||||
@@ -1,28 +1,99 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopOrderStatistic;
|
||||
import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService{
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getCreateTime, startOfDay)
|
||||
.le(OrderInfo::getCreateTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
HashMap<Long, ShopOrderStatistic> countInfo = new HashMap<>();
|
||||
for (OrderInfo item : orderInfos) {
|
||||
ShopOrderStatistic statisticTask = countInfo.get(item.getShopId());
|
||||
if (statisticTask == null) {
|
||||
countInfo.put(item.getShopId(), statisticTask = new ShopOrderStatistic());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getRefundAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount() + 1);
|
||||
if (item.getRefundAmount().compareTo(item.getPayAmount()) < 0) {
|
||||
statisticTask.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
|
||||
}
|
||||
} else {
|
||||
statisticTask.setSaleCount(statisticTask.getSaleCount() + 1);
|
||||
statisticTask.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount()));
|
||||
}
|
||||
|
||||
switch (item.getPayType()) {
|
||||
case "wechat-mini":
|
||||
statisticTask.setWechatPayAmount(statisticTask.getWechatPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setWechatPayCount(statisticTask.getWechatPayCount() + 1);
|
||||
break;
|
||||
case "main-scan", "back-scan":
|
||||
statisticTask.setScanPayAmount(statisticTask.getScanPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setScanPayCount(statisticTask.getScanPayCount() + 1);
|
||||
break;
|
||||
case "alipay-mini":
|
||||
statisticTask.setAliPayAmount(statisticTask.getAliPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setAliPayCount(statisticTask.getAliPayCount() + 1);
|
||||
break;
|
||||
case "vip-pay":
|
||||
statisticTask.setMemberPayAmount(statisticTask.getMemberPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setMemberPayCount(statisticTask.getMemberPayCount() + 1);
|
||||
break;
|
||||
case "credit-pay":
|
||||
statisticTask.setCreditPayAmount(statisticTask.getCreditPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setCreditPayCount(statisticTask.getCreditPayCount() + 1);
|
||||
break;
|
||||
case "cash-pay":
|
||||
statisticTask.setCashPayAmount(statisticTask.getCashPayAmount().add(item.getPayAmount()));
|
||||
statisticTask.setCashPayCount(statisticTask.getCashPayCount() + 1);
|
||||
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, info) -> {
|
||||
ShopOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopOrderStatistic();
|
||||
}
|
||||
BeanUtil.copyProperties(info, statistic);
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user