mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
支付宝登录
This commit is contained in:
@@ -131,10 +131,11 @@ public class MemberController extends BaseController {
|
||||
|
||||
/**
|
||||
* 支付寶一键登录
|
||||
* http://localhost:8080/uniapp/member/wechatLogin
|
||||
* http://localhost:8080/uniapp/member/alipayLogin
|
||||
*/
|
||||
@PostMapping("/alipayLogin")
|
||||
public RestApiResponse<?> alipayLogin(HttpServletRequest request, @RequestBody WechatLoginDTO dto) {
|
||||
public RestApiResponse<?> alipayLogin(HttpServletRequest request, @RequestBody AlipayLoginDTO dto) {
|
||||
logger.info("支付宝小程序登录param:{}", JSON.toJSONString(dto));
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
// 获取小程序appid
|
||||
@@ -144,7 +145,7 @@ public class MemberController extends BaseController {
|
||||
response = new RestApiResponse<>(ImmutableMap.of("memberToken", memberToken));
|
||||
} catch (Exception e) {
|
||||
logger.error("支付宝登录异常 param:{}", JSON.toJSONString(dto), e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WECHAT_LOGIN_ERROR);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_ALIPAY_LOGIN_ERROR);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -199,21 +200,21 @@ public class MemberController extends BaseController {
|
||||
* 获取openId
|
||||
* http://localhost:8080/uniapp/member/getOpenId
|
||||
*/
|
||||
@PostMapping("/getOpenId")
|
||||
public RestApiResponse<?> getOpenId(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
||||
logger.info("获取openId param:{}", dto.toString());
|
||||
RestApiResponse<?> response;
|
||||
try {
|
||||
getMemberIdByAuthorization(request);
|
||||
String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||
response = new RestApiResponse<>(ImmutableMap.of("openId", openId));
|
||||
} catch (Exception e) {
|
||||
logger.error("获取openId error", e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
}
|
||||
logger.info("获取openId result:{}", response);
|
||||
return response;
|
||||
}
|
||||
// @PostMapping("/getOpenId")
|
||||
// public RestApiResponse<?> getOpenId(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
||||
// logger.info("获取openId param:{}", dto.toString());
|
||||
// RestApiResponse<?> response;
|
||||
// try {
|
||||
// getMemberIdByAuthorization(request);
|
||||
// String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||
// response = new RestApiResponse<>(ImmutableMap.of("openId", openId));
|
||||
// } catch (Exception e) {
|
||||
// logger.error("获取openId error", e);
|
||||
// response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
// }
|
||||
// logger.info("获取openId result:{}", response);
|
||||
// return response;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,47 +61,47 @@ public class PayController extends BaseController {
|
||||
* http://localhost:8080/uniapp/pay/weixinPay
|
||||
* @deprecated 使用汇付支付,充值余额
|
||||
*/
|
||||
@PostMapping("/weixinPay")
|
||||
public RestApiResponse<?> weixinPay(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
||||
logger.info("微信支付 param:{}", dto.toString());
|
||||
RestApiResponse<?> response;
|
||||
try {
|
||||
if (dto != null) {
|
||||
throw new BusinessException("00500005", "充值功能维护,已有余额可用,推荐使用在线支付");
|
||||
}
|
||||
if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
||||
}
|
||||
// 鉴权
|
||||
String memberId = getMemberIdByAuthorization(request);
|
||||
if (StringUtils.isBlank(memberId)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
||||
}
|
||||
dto.setMemberId(memberId);
|
||||
// String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMemberId(memberId);
|
||||
if (memberBasicInfo == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
}
|
||||
String openId = memberBasicInfo.getOpenId();
|
||||
dto.setOpenId(openId);
|
||||
// 充值余额 附加参数
|
||||
PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
|
||||
paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
|
||||
paymentScenarioDTO.setMemberId(memberId);
|
||||
dto.setAttach(JSON.toJSONString(paymentScenarioDTO));
|
||||
dto.setDescription("会员充值余额");
|
||||
Map<String, Object> weixinMap = orderService.weixinPayV3(dto);
|
||||
response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
|
||||
} catch (BusinessException e) {
|
||||
logger.warn("充值余额支付warn", e);
|
||||
response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.warn("充值余额支付error", e);
|
||||
response = new RestApiResponse<>();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
// @PostMapping("/weixinPay")
|
||||
// public RestApiResponse<?> weixinPay(HttpServletRequest request, @RequestBody WeixinPayDTO dto) {
|
||||
// logger.info("微信支付 param:{}", dto.toString());
|
||||
// RestApiResponse<?> response;
|
||||
// try {
|
||||
// if (dto != null) {
|
||||
// throw new BusinessException("00500005", "充值功能维护,已有余额可用,推荐使用在线支付");
|
||||
// }
|
||||
// if (StringUtils.isBlank(dto.getCode()) || StringUtils.isBlank(dto.getAmount())) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
||||
// }
|
||||
// // 鉴权
|
||||
// String memberId = getMemberIdByAuthorization(request);
|
||||
// if (StringUtils.isBlank(memberId)) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
||||
// }
|
||||
// dto.setMemberId(memberId);
|
||||
// // String openId = memberService.getOpenIdByCode(dto.getCode());
|
||||
// MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMemberId(memberId);
|
||||
// if (memberBasicInfo == null) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_GET_OPEN_ID_BY_CODE_ERROR);
|
||||
// }
|
||||
// String openId = memberBasicInfo.getOpenId();
|
||||
// dto.setOpenId(openId);
|
||||
// // 充值余额 附加参数
|
||||
// PaymentScenarioDTO paymentScenarioDTO = new PaymentScenarioDTO();
|
||||
// paymentScenarioDTO.setType(ScenarioEnum.BALANCE.getValue());
|
||||
// paymentScenarioDTO.setMemberId(memberId);
|
||||
// dto.setAttach(JSON.toJSONString(paymentScenarioDTO));
|
||||
// dto.setDescription("会员充值余额");
|
||||
// Map<String, Object> weixinMap = orderService.weixinPayV3(dto);
|
||||
// response = new RestApiResponse<>(ImmutableMap.of("weixinMap", weixinMap));
|
||||
// } catch (BusinessException e) {
|
||||
// logger.warn("充值余额支付warn", e);
|
||||
// response = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// logger.warn("充值余额支付error", e);
|
||||
// response = new RestApiResponse<>();
|
||||
// }
|
||||
// return response;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 7002 支付订单
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.util.PageUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -13,6 +14,7 @@ import com.huifu.adapay.model.Payment;
|
||||
import com.jsowell.adapay.common.CreateAdaPaymentParam;
|
||||
import com.jsowell.adapay.config.AbstractAdapayConfig;
|
||||
import com.jsowell.adapay.factory.AdapayConfigFactory;
|
||||
import com.jsowell.alipay.service.AliAppletRemoteService;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.constant.UserConstants;
|
||||
@@ -76,6 +78,9 @@ public class MemberService {
|
||||
@Autowired
|
||||
private WxAppletRemoteService wxAppletRemoteService;
|
||||
|
||||
@Autowired
|
||||
private AliAppletRemoteService aliAppletRemoteService;
|
||||
|
||||
@Autowired
|
||||
private MemberPlateNumberRelationService memberPlateNumberRelationService;
|
||||
|
||||
@@ -146,9 +151,12 @@ public class MemberService {
|
||||
if (StringUtils.isBlank(firstLevelMerchantId)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR);
|
||||
}
|
||||
if (StringUtils.isBlank(openId)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_OPEN_ID_IS_NULL_ERROR);
|
||||
}
|
||||
|
||||
// 2024年6月11日15点37分 支付宝没有openid,改为不校验openid
|
||||
// if (StringUtils.isBlank(openId)) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_OPEN_ID_IS_NULL_ERROR);
|
||||
// }
|
||||
|
||||
// 查询手机号码是否注册过
|
||||
MemberBasicInfo memberBasicInfo = memberBasicInfoService.selectInfoByMobileNumber(phoneNumber, firstLevelMerchantId);
|
||||
if (Objects.isNull(memberBasicInfo)) {
|
||||
@@ -160,7 +168,9 @@ public class MemberService {
|
||||
memberBasicInfo.setNickName("会员" + memberId);
|
||||
memberBasicInfo.setMobileNumber(phoneNumber);
|
||||
memberBasicInfo.setMerchantId(Long.valueOf(firstLevelMerchantId));
|
||||
memberBasicInfo.setOpenId(openId);
|
||||
if (StringUtils.isBlank(openId)) {
|
||||
memberBasicInfo.setOpenId(openId);
|
||||
}
|
||||
|
||||
MemberTransactionDTO memberTransactionDTO = new MemberTransactionDTO();
|
||||
memberTransactionDTO.setMemberBasicInfo(memberBasicInfo);
|
||||
@@ -208,26 +218,28 @@ public class MemberService {
|
||||
if (StringUtils.isBlank(mobileNumber)) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_GET_MOBILE_NUMBER_BY_CODE_ERROR);
|
||||
}
|
||||
// 通过appid获取运营商id
|
||||
// String merchantId = pileMerchantInfoService.getMerchantIdByAppId(dto.getAppId());
|
||||
// if (Objects.isNull(merchantId)) {
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_GET_MERCHANT_ID_BY_APP_ID_ERROR);
|
||||
// }
|
||||
// 通过code获取openId
|
||||
String openId = "";
|
||||
try {
|
||||
openId = getOpenIdByCode(dto.getOpenIdCode());
|
||||
openId = wxAppletRemoteService.getOpenIdByCode(dto.getOpenIdCode());
|
||||
} catch (Exception e) {
|
||||
log.error("getOpenIdByCode发生异常", e);
|
||||
}
|
||||
// 根据appid查询merchantId
|
||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(APP_ID);
|
||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
|
||||
// 查询手机号码是否注册过
|
||||
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, openId);
|
||||
}
|
||||
|
||||
public String alipayLogin(WechatLoginDTO dto) {
|
||||
return "";
|
||||
public String alipayLogin(AlipayLoginDTO dto) throws Exception {
|
||||
// 通过密文解密 获取手机号码
|
||||
String mobileNumber = Factory.Util.AES().decrypt(dto.getMobileNumberCiphertext());
|
||||
|
||||
// 根据appid查询merchantId
|
||||
String firstLevelMerchantId = pileMerchantInfoService.getFirstLevelMerchantIdByAppId(dto.getAppId());
|
||||
|
||||
// 查询手机号码是否注册过
|
||||
return memberRegisterAndLogin(mobileNumber, firstLevelMerchantId, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,9 +247,9 @@ public class MemberService {
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public String getOpenIdByCode(String code) {
|
||||
return wxAppletRemoteService.getOpenIdByCode(code);
|
||||
}
|
||||
// public String getOpenIdByCode(String code) {
|
||||
// return wxAppletRemoteService.getOpenIdByCode(code);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 处理用户信息
|
||||
|
||||
@@ -208,3 +208,5 @@ alipay:
|
||||
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt5iUV9VA5EDCMFZlxMlZ2NHvkPdwmRwTzN1rNGlf/VITTBvt1F61nQBjTlUIDVxvd77Zs9bS4bA/k2rpo0luDRQeSSgZ5xHDA6A0E4gcwik54s/Ic6DIWGpod/Ci6sSLpq8Fn9/jnR4k12sr4fzQOANdwwnlEtrynLa7j94IWeXeIqXFenLamswqvvwSuMWsVzxub/gXpjeY5t6pzRKxFoh9Cpf6e2lMP3vP8thr+kSYH/37OWndJZw0I1FW+aZzLmERCA/T4wK7u4tVIeLK9xlKGtV1CHki8PjRAazXWEXmoN7dtFGTi5xBBkHof38CVAe94QOn4XSwyegiyA5A3QIDAQAB
|
||||
# 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
notifyUrl: xxxx
|
||||
# AES密钥
|
||||
encryptKey: 0TOgnthQKQtoXJaSn5Bbhg==
|
||||
|
||||
@@ -202,4 +202,6 @@ alipay:
|
||||
# 支付宝公钥
|
||||
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt5iUV9VA5EDCMFZlxMlZ2NHvkPdwmRwTzN1rNGlf/VITTBvt1F61nQBjTlUIDVxvd77Zs9bS4bA/k2rpo0luDRQeSSgZ5xHDA6A0E4gcwik54s/Ic6DIWGpod/Ci6sSLpq8Fn9/jnR4k12sr4fzQOANdwwnlEtrynLa7j94IWeXeIqXFenLamswqvvwSuMWsVzxub/gXpjeY5t6pzRKxFoh9Cpf6e2lMP3vP8thr+kSYH/37OWndJZw0I1FW+aZzLmERCA/T4wK7u4tVIeLK9xlKGtV1CHki8PjRAazXWEXmoN7dtFGTi5xBBkHof38CVAe94QOn4XSwyegiyA5A3QIDAQAB
|
||||
# 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
notifyUrl: xxxx
|
||||
notifyUrl: xxxx
|
||||
# AES密钥
|
||||
encryptKey: 0TOgnthQKQtoXJaSn5Bbhg==
|
||||
@@ -202,4 +202,6 @@ alipay:
|
||||
# 支付宝公钥
|
||||
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt5iUV9VA5EDCMFZlxMlZ2NHvkPdwmRwTzN1rNGlf/VITTBvt1F61nQBjTlUIDVxvd77Zs9bS4bA/k2rpo0luDRQeSSgZ5xHDA6A0E4gcwik54s/Ic6DIWGpod/Ci6sSLpq8Fn9/jnR4k12sr4fzQOANdwwnlEtrynLa7j94IWeXeIqXFenLamswqvvwSuMWsVzxub/gXpjeY5t6pzRKxFoh9Cpf6e2lMP3vP8thr+kSYH/37OWndJZw0I1FW+aZzLmERCA/T4wK7u4tVIeLK9xlKGtV1CHki8PjRAazXWEXmoN7dtFGTi5xBBkHof38CVAe94QOn4XSwyegiyA5A3QIDAQAB
|
||||
# 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
notifyUrl: xxxx
|
||||
notifyUrl: xxxx
|
||||
# AES密钥
|
||||
encryptKey: 0TOgnthQKQtoXJaSn5Bbhg==
|
||||
@@ -205,4 +205,6 @@ alipay:
|
||||
# 支付宝公钥
|
||||
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt5iUV9VA5EDCMFZlxMlZ2NHvkPdwmRwTzN1rNGlf/VITTBvt1F61nQBjTlUIDVxvd77Zs9bS4bA/k2rpo0luDRQeSSgZ5xHDA6A0E4gcwik54s/Ic6DIWGpod/Ci6sSLpq8Fn9/jnR4k12sr4fzQOANdwwnlEtrynLa7j94IWeXeIqXFenLamswqvvwSuMWsVzxub/gXpjeY5t6pzRKxFoh9Cpf6e2lMP3vP8thr+kSYH/37OWndJZw0I1FW+aZzLmERCA/T4wK7u4tVIeLK9xlKGtV1CHki8PjRAazXWEXmoN7dtFGTi5xBBkHof38CVAe94QOn4XSwyegiyA5A3QIDAQAB
|
||||
# 服务器异步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
notifyUrl: xxxx
|
||||
notifyUrl: xxxx
|
||||
# AES密钥
|
||||
encryptKey: 0TOgnthQKQtoXJaSn5Bbhg==
|
||||
@@ -1,7 +1,11 @@
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipayEncrypt;
|
||||
import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
@@ -259,21 +263,38 @@ public class SpringBootTestController {
|
||||
private NotificationService notificationService;
|
||||
|
||||
@Test
|
||||
public void alipayLoginTest() {
|
||||
String refreshToken = "";
|
||||
String auth_code = "354109ecc25f4d9f943331578f56XD91";
|
||||
try {
|
||||
// AlipaySystemOauthTokenResponse alipaySystemOauthTokenResponse = Factory.Base.OAuth().refreshToken(refreshToken);
|
||||
// System.out.println(JSON.toJSONString(alipaySystemOauthTokenResponse));
|
||||
AlipaySystemOauthTokenResponse token = Factory.Base.OAuth().getToken(auth_code);
|
||||
System.out.println(JSON.toJSONString(token));
|
||||
} catch (Exception e) {
|
||||
if (e instanceof TeaUnretryableException) {
|
||||
TeaUnretryableException exception = (TeaUnretryableException) e;
|
||||
logger.error("TeaUnretryableException异常:{}", exception.getLastRequest());
|
||||
public void decryptPhoneNum(){
|
||||
// 前端接口返回的加密信息
|
||||
String response ="{\"response\":\"CunEGSbDxsQaKllc35Q+4lJdLiprZhrHFt9erZriETVHv2IrtZsmC8cA6DE5l8GgzvgHCPdGp1iUJQhNyKog==\",\"sign\":\"BlmgjdRvvifS1d9LGcVzq66P7vYrpRHrSCY1SX8zDfU4vEiN4Kz9otxGA4Hz6vG0SoBdlg+Nc58JVUP1IXzQUIFrvAYLC2Uty9J60RmvyWjUf+1Njt7ifX5JgqhMPGOoz3H1OQ1NiqjT6L93KTHYjLt8q37U1aTBO72lQQRgSk0Yf+z1RbalBgRLXHYrgQNORoqJZNN4emQ0a63B30FAFbbko1JbR5eToLK2EcT7vG5rN7wH+3XGTeQ0em81ryNXYUjf7sKLDTsPu7Irk3okOiWMVUr83d3wkST9JWjnO5H7Advh0DaHA1aQnT9oKm82lcUA0r9eE8kqfTmuQ==\"}";
|
||||
//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 = openapiResult.get("response");
|
||||
// 判断是否为加密内容
|
||||
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();
|
||||
}
|
||||
}
|
||||
logger.error("Exception", e);
|
||||
} else {
|
||||
plainData = content;
|
||||
}
|
||||
System.out.println(plainData);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2892,18 +2913,18 @@ public class SpringBootTestController {
|
||||
|
||||
@Test
|
||||
public void testPay() {
|
||||
String code = "081zIoGa11GamE0iVVIa1aaJ4G0zIoGE";
|
||||
String openId = memberService.getOpenIdByCode(code);
|
||||
Map<String, Object> pay = null;
|
||||
try {
|
||||
WeixinPayDTO dto = new WeixinPayDTO();
|
||||
dto.setOpenId(openId);
|
||||
dto.setAmount("0.01");
|
||||
pay = orderService.weixinPayV3(dto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(JSON.toJSONString(pay));
|
||||
// String code = "081zIoGa11GamE0iVVIa1aaJ4G0zIoGE";
|
||||
// String openId = memberService.getOpenIdByCode(code);
|
||||
// Map<String, Object> pay = null;
|
||||
// try {
|
||||
// WeixinPayDTO dto = new WeixinPayDTO();
|
||||
// dto.setOpenId(openId);
|
||||
// dto.setAmount("0.01");
|
||||
// pay = orderService.weixinPayV3(dto);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// System.out.println(JSON.toJSONString(pay));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,8 @@ public enum ReturnCodeEnum {
|
||||
|
||||
CODE_WECHAT_LOGIN_ERROR("00100008", "微信登录异常"),
|
||||
|
||||
|
||||
|
||||
CODE_GET_MEMBER_PHONE_NUMBER_ERROR("00100009", "获取用户手机号异常"),
|
||||
|
||||
CODE_HANDLE_USER_INFO_ERROR("00100010", "处理用户信息异常"),
|
||||
@@ -137,6 +139,8 @@ public enum ReturnCodeEnum {
|
||||
|
||||
CODE_GET_MEMBER_CAR_NO_INFO_ERROR("00100064", "通过 memberId 查询用户绑定车牌信息失败"),
|
||||
|
||||
CODE_ALIPAY_LOGIN_ERROR("00100065", "支付宝登录异常"),
|
||||
|
||||
/* 个人桩 start */
|
||||
|
||||
CODE_PILE_HAS_BEEN_BINDING_ERROR("00400001", "此桩已被绑定,请联系管理员!"),
|
||||
|
||||
@@ -28,6 +28,9 @@ public class AliPayConfig implements CommandLineRunner {
|
||||
@Value("${alipay.notifyUrl}")
|
||||
private String notifyUrl;
|
||||
|
||||
@Value("${alipay.encryptKey}")
|
||||
private String encryptKey;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
log.info(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 AliPayConfig order 2 <<<<<<<<<<<<<");
|
||||
@@ -50,8 +53,9 @@ public class AliPayConfig implements CommandLineRunner {
|
||||
config.alipayPublicKey = alipayPublicKey;
|
||||
// 可设置异步通知接收服务地址(可选)
|
||||
// config.notifyUrl = "<-- 请填写您的支付类接口异步通知接收服务地址,例如:https://www.test.com/callback -->";
|
||||
|
||||
// 可设置AES密钥,调用AES加解密相关接口时需要(可选)
|
||||
// config.encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->";
|
||||
config.encryptKey = encryptKey;
|
||||
Factory.setOptions(config);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
package com.jsowell.alipay.service;
|
||||
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.internal.util.AlipayEncrypt;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.jsowell.alipay.config.AliPayConfig;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.response.RestApiResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,36 +27,34 @@ import java.util.Map;
|
||||
/**
|
||||
* 支付宝小程序service
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AliAppletRemoteService {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(AliAppletRemoteService.class);
|
||||
/**
|
||||
* 通过authCode获取手机号
|
||||
* @param code
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getMobileNumberByCode(String code) throws Exception {
|
||||
AlipaySystemOauthTokenResponse token = Factory.Base.OAuth().getToken(code);
|
||||
log.info("AlipaySystemOauthTokenResponse:{}", JSON.toJSONString(token));
|
||||
|
||||
String accessToken = token.getAccessToken();
|
||||
|
||||
// Factory.Util.AES().decrypt();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* (支付宝) 换取授权访问令牌
|
||||
* alipay.system.oauth.token(换取授权访问令牌)
|
||||
* 通过openIdCode获取openId
|
||||
* @param openIdCode
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("getInfo")
|
||||
public RestApiResponse<?> getInfo(String auth_code) throws AlipayApiException {
|
||||
RestApiResponse<?> restApiResponse;
|
||||
try {
|
||||
if(auth_code==null||auth_code.length()==0) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
|
||||
}
|
||||
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("userid", "");
|
||||
restApiResponse = new RestApiResponse<>(map);
|
||||
} catch (BusinessException e) {
|
||||
restApiResponse = new RestApiResponse<>(e.getCode(), e.getMessage());
|
||||
} catch (Exception e) {
|
||||
restApiResponse = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);
|
||||
}
|
||||
|
||||
return restApiResponse;
|
||||
public String getOpenId(String openIdCode) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.jsowell.pile.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlipayLoginDTO {
|
||||
/**
|
||||
* 手机号密文
|
||||
*/
|
||||
private String mobileNumberCiphertext;
|
||||
|
||||
/**
|
||||
* 小程序appId
|
||||
*/
|
||||
private String appId;
|
||||
}
|
||||
@@ -7,8 +7,14 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class WechatLoginDTO {
|
||||
/**
|
||||
* 前端获取到的authCode
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 小程序appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user