mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-10 21:10:24 +08:00
支付宝登录
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.jsowell.api.uniapp;
|
package com.jsowell.api.uniapp;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.jsowell.common.annotation.Anonymous;
|
import com.jsowell.common.annotation.Anonymous;
|
||||||
@@ -81,12 +80,12 @@ public class MemberController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/memberRegisterAndLogin")
|
@PostMapping("/memberRegisterAndLogin")
|
||||||
public RestApiResponse<?> memberRegisterAndLogin(HttpServletRequest request, @RequestBody MemberRegisterAndLoginDTO dto) {
|
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;
|
RestApiResponse<?> response = null;
|
||||||
try {
|
try {
|
||||||
String appId = request.getHeader("appId");
|
String appId = request.getHeader("appId");
|
||||||
if (StringUtils.isNotBlank(appId)) {
|
if (StringUtils.isNotBlank(appId)) {
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
|
||||||
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
|
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
|
||||||
dto.setMerchantId(firstLevelMerchantId);
|
dto.setMerchantId(firstLevelMerchantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class PersonPileController extends BaseController {
|
|||||||
try {
|
try {
|
||||||
String appId = request.getHeader("appId");
|
String appId = request.getHeader("appId");
|
||||||
if (StringUtils.isNotBlank(appId)) {
|
if (StringUtils.isNotBlank(appId)) {
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
|
||||||
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
|
if (StringUtils.isNotBlank(firstLevelMerchantId)) {
|
||||||
dto.setMerchantId(firstLevelMerchantId);
|
dto.setMerchantId(firstLevelMerchantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -636,7 +636,7 @@ public class AgentDevService {
|
|||||||
// 获取openId
|
// 获取openId
|
||||||
String openId = getOpenIdByCode(dto.getOpenIdCode(), appId);
|
String openId = getOpenIdByCode(dto.getOpenIdCode(), appId);
|
||||||
// 通过 appid 查询 merchantId
|
// 通过 appid 查询 merchantId
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(appId);
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(appId);
|
||||||
logger.info("微信一键登录 获取merchantId:{}", firstLevelMerchantId);
|
logger.info("微信一键登录 获取merchantId:{}", firstLevelMerchantId);
|
||||||
// 下面方法有判断 merchantId 是否为空,因此可直接传值
|
// 下面方法有判断 merchantId 是否为空,因此可直接传值
|
||||||
return memberService.memberRegisterAndLogin(phoneNumber, firstLevelMerchantId, openId);
|
return memberService.memberRegisterAndLogin(phoneNumber, firstLevelMerchantId, openId);
|
||||||
|
|||||||
@@ -227,17 +227,19 @@ public class MemberService {
|
|||||||
log.error("getOpenIdByCode发生异常", e);
|
log.error("getOpenIdByCode发生异常", e);
|
||||||
}
|
}
|
||||||
// 根据appid查询merchantId
|
// 根据appid查询merchantId
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
|
||||||
// 查询手机号码是否注册过
|
// 查询手机号码是否注册过
|
||||||
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, openId);
|
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, openId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String alipayLogin(AlipayLoginDTO dto) throws Exception {
|
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
|
// 根据appid查询merchantId
|
||||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
|
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
|
||||||
|
firstLevelMerchantId = "1";
|
||||||
|
|
||||||
// 查询手机号码是否注册过
|
// 查询手机号码是否注册过
|
||||||
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, "");
|
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, "");
|
||||||
|
|||||||
@@ -263,38 +263,12 @@ public class SpringBootTestController {
|
|||||||
private NotificationService notificationService;
|
private NotificationService notificationService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decryptPhoneNum(){
|
public void decryptPhoneNum() throws Exception {
|
||||||
// 前端接口返回的加密信息
|
|
||||||
String response ="CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
|
String content = "/CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9er/ZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==";
|
||||||
//1. 获取解密所需要的参数
|
// 通过密文解密 获取手机号码
|
||||||
Map<String, String> openapiResult = com.alibaba.fastjson.JSON.parseObject(response, new TypeReference<Map<String, String>>() {}, Feature.OrderedField);
|
String mobileNumber = Factory.Util.AES().decrypt(content);
|
||||||
String charset = "UTF-8";
|
System.out.println(mobileNumber);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public interface PileMerchantInfoService {
|
|||||||
* @param appId 微信小程序appId
|
* @param appId 微信小程序appId
|
||||||
* @return 一级运营商merchantId
|
* @return 一级运营商merchantId
|
||||||
*/
|
*/
|
||||||
String getFirstLevelMerchantIdByAppId(String appId);
|
String getFirstLevelMerchantIdByWxAppId(String appId);
|
||||||
|
|
||||||
MerchantInfoVO getMerchantInfoVO(String merchantId);
|
MerchantInfoVO getMerchantInfoVO(String merchantId);
|
||||||
|
|
||||||
|
|||||||
@@ -3480,7 +3480,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
|||||||
|
|
||||||
if (StringUtils.isNotBlank(dto.getAppId())) {
|
if (StringUtils.isNotBlank(dto.getAppId())) {
|
||||||
// 校验启动桩使用的小程序,和充电桩所属一级运营商是否一致
|
// 校验启动桩使用的小程序,和充电桩所属一级运营商是否一致
|
||||||
String merchantIdByAppId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
|
String merchantIdByAppId = pileMerchantInfoService.getFirstLevelMerchantIdByWxAppId(dto.getAppId());
|
||||||
String merchantIdByMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByMerchantId(stationInfo.getMerchantId());
|
String merchantIdByMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByMerchantId(stationInfo.getMerchantId());
|
||||||
if (!StringUtils.equals(merchantIdByAppId, merchantIdByMerchantId)) {
|
if (!StringUtils.equals(merchantIdByAppId, merchantIdByMerchantId)) {
|
||||||
throw new BusinessException("", "当前桩运营商与小程序所属运营商不一致");
|
throw new BusinessException("", "当前桩运营商与小程序所属运营商不一致");
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ public class PileMerchantInfoServiceImpl implements PileMerchantInfoService {
|
|||||||
* @return 一级运营商merchantId
|
* @return 一级运营商merchantId
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getFirstLevelMerchantIdByAppId(String appId) {
|
public String getFirstLevelMerchantIdByWxAppId(String appId) {
|
||||||
String merchantId = null;
|
String merchantId = null;
|
||||||
PileMerchantInfo merchant = getFirstLevelMerchantByAppId(appId);
|
PileMerchantInfo merchant = getFirstLevelMerchantByAppId(appId);
|
||||||
if (Objects.nonNull(merchant)) {
|
if (Objects.nonNull(merchant)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user