支付宝登录

This commit is contained in:
Guoqs
2024-06-11 17:01:44 +08:00
parent 0290db1914
commit 6d5b436393
8 changed files with 18 additions and 43 deletions

View File

@@ -1,7 +1,6 @@
package com.jsowell.api.uniapp;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.jsowell.common.annotation.Anonymous;
@@ -81,12 +80,12 @@ public class MemberController extends BaseController {
*/
@PostMapping("/memberRegisterAndLogin")
public RestApiResponse<?> memberRegisterAndLogin(HttpServletRequest request, @RequestBody MemberRegisterAndLoginDTO dto) {
logger.info("会员登录注册接口 param:{}", JSON.toJSONString(dto));
logger.info("会员登录注册接口 param:{}, user-agent:{}", JSON.toJSONString(dto), request.getHeader("user-agent"));
RestApiResponse<?> response = null;
try {
String appId = request.getHeader("appId");
if (StringUtils.isNotBlank(appId)) {
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
dto.setMerchantId(firstLevelMerchantId);
}

View File

@@ -114,7 +114,7 @@ public class PersonPileController extends BaseController {
try {
String appId = request.getHeader("appId");
if (StringUtils.isNotBlank(appId)) {
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
dto.setMerchantId(firstLevelMerchantId);
}

View File

@@ -636,7 +636,7 @@ public class AgentDevService {
// 获取openId
String openId = getOpenIdByCode(dto.getOpenIdCode(), appId);
// 通过 appid 查询 merchantId
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
logger.info("微信一键登录 获取merchantId:{}", firstLevelMerchantId);
// 下面方法有判断 merchantId 是否为空,因此可直接传值
return memberService.memberRegisterAndLogin(phoneNumber, firstLevelMerchantId, openId);

View File

@@ -227,17 +227,19 @@ public class MemberService {
log.error("getOpenIdByCode发生异常", e);
}
// 根据appid查询merchantId
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
// 查询手机号码是否注册过
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, openId);
}
public String alipayLogin(AlipayLoginDTO dto) throws Exception {
// 通过密文解密 获取手机号码
String mobileNumber = Factory.Util.AES().decrypt(dto.getMobileNumberCiphertext());
String decrypt = Factory.Util.AES().decrypt(dto.getMobileNumberCiphertext());
String mobileNumber = JSON.parseObject(decrypt).getString("mobile");
// 根据appid查询merchantId
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
firstLevelMerchantId = "1";
// 查询手机号码是否注册过
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, "");

View File

@@ -263,38 +263,12 @@ public class SpringBootTestController {
private NotificationService notificationService;
@Test
public void decryptPhoneNum(){
// 前端接口返回的加密信息
String response ="CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
//1. 获取解密所需要的参数
Map<String, String> openapiResult = com.alibaba.fastjson.JSON.parseObject(response, new TypeReference<Map<String, String>>() {}, Feature.OrderedField);
String charset = "UTF-8";
String encryptType = "AES";
String content = "CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
// 判断是否为加密内容
boolean isDataEncrypted = !content.startsWith("{");
String decryptKey = "B_AES_KEY"; // 商家小程序 AES 密钥
//AES密钥这里参数不能写成固定的开发阶段需传入模板的AES密钥实例化后应传入商家小程序的AES密钥
// 解密
String plainData = null;
if (isDataEncrypted) {
try {
System.out.println("AlipayEncrypt");
plainData = AlipayEncrypt.decryptContent(content, encryptType, decryptKey,charset);
System.out.println("AlipayEncrypt Trance done");
} catch (AlipayApiException e) {
//解密异常, 记录日志
try {
throw new Exception("解密异常");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} else {
plainData = content;
}
System.out.println(plainData);
public void decryptPhoneNum() throws Exception {
String content = "/CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
// 通过密文解密 获取手机号码
String mobileNumber = Factory.Util.AES().decrypt(content);
System.out.println(mobileNumber);
}
@Test