refactor(payment): 支付宝绑定相关功能
parent
32a50b8394
commit
40eb64b043
|
@ -92,13 +92,19 @@ public class AliPayController extends BaseController {
|
|||
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
|
||||
|
||||
String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
|
||||
// 线上
|
||||
// String authUrl = String.format(
|
||||
// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
// appId, scope, encodedRedirectUri, state
|
||||
// );
|
||||
// 沙箱
|
||||
String authUrl = String.format(
|
||||
"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
"https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
|
||||
appId, scope, encodedRedirectUri, state
|
||||
);
|
||||
|
||||
// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
|
||||
return R.ok("成功", authUrl);
|
||||
return R.ok(authUrl, "成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,6 +112,7 @@ public class AliPayController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/queryBindStatus")
|
||||
@ApiOperation(value = "支付宝绑定状态查询")
|
||||
@ResponseBody
|
||||
public R<Object> queryTradeStatus() throws Exception {
|
||||
|
||||
return aliPayService.queryBindStatus();
|
||||
|
|
|
@ -129,7 +129,6 @@ public class SecurityConfig {
|
|||
requests.antMatchers("/login",
|
||||
"/register",
|
||||
"/captchaImage",
|
||||
"/ali/pay/doPay",
|
||||
"/ali/pay/notify",
|
||||
"/ali/pay/callback",
|
||||
"/file/**",
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
|||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.response.AlipayFundAccountQueryResponse;
|
||||
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
|
||||
|
@ -200,7 +201,8 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
tradeEntity.getCode(),
|
||||
orderTradeDto.getAmount().toString());
|
||||
// 缓存到redis
|
||||
redisCache.setCacheObject(tradeEntity.getCode() + "_promotionId", orderTradeDto.getPromotionId());
|
||||
if (Objects.nonNull(orderTradeDto.getPromotionId()))
|
||||
redisCache.setCacheObject(tradeEntity.getCode() + "_promotionId", orderTradeDto.getPromotionId(), 15, TimeUnit.MINUTES);
|
||||
// AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace().preCreate("订单主题:Mac笔记本", "LS123qwe123", "19999");
|
||||
//参照官方文档响应示例,解析返回结果
|
||||
String httpBodyStr = payResponse.getHttpBody();
|
||||
|
@ -308,11 +310,11 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
.one();
|
||||
|
||||
if (Objects.isNull(sysUserPayAccount)) {
|
||||
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
|
||||
return R.ok(0);
|
||||
redisCache.setCacheObject("alipay:bind:user:status:" + SecurityUtils.getUserId(), "0", 4, TimeUnit.SECONDS);
|
||||
return R.ok("0");
|
||||
}
|
||||
redisCache.setCacheObject("alipay:bind:user:status:", 1, 4, TimeUnit.SECONDS);
|
||||
return R.ok(1);
|
||||
redisCache.setCacheObject("alipay:bind:user:status:" + SecurityUtils.getUserId(), "1", 4, TimeUnit.SECONDS);
|
||||
return R.ok("1");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -467,7 +469,7 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
request.setCode(authCode);
|
||||
request.setGrantType("authorization_code");
|
||||
com.alipay.api.response.AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
|
||||
AlipaySystemOauthTokenResponse response = alipayClient.certificateExecute(request);
|
||||
if (response.isSuccess()) {
|
||||
// 支付宝用户唯一ID
|
||||
String openId = response.getOpenId();
|
||||
|
@ -487,15 +489,14 @@ public class AliPayServiceImpl implements AliPayService {
|
|||
userPayAccount.setOpenId(openId);
|
||||
userPayAccount.setType(0);
|
||||
sysUserPayAccountService.save(userPayAccount);
|
||||
redisCache.setCacheObject("alipay:bind:user:status:", 1, 4, TimeUnit.SECONDS);
|
||||
redisCache.setCacheObject("alipay:bind:user:status:" + userId, "1", 4, TimeUnit.SECONDS);
|
||||
return "success";
|
||||
} else {
|
||||
System.out.println("绑定失败:" + response.getSubMsg());
|
||||
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
|
||||
redisCache.setCacheObject("alipay:bind:user:status:" + userId, "0", 4, TimeUnit.SECONDS);
|
||||
return "fail";
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
|||
if (OrderTypeEnum.POINTS.getName().equals(suffix)) {
|
||||
pointsHandler(orderTrade, params);
|
||||
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
|
||||
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "promotionId");
|
||||
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "_promotionId");
|
||||
memberHandler(orderTrade, promotionId);
|
||||
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
|
||||
} else if (OrderTypeEnum.WALLET.getName().equals(suffix)) {
|
||||
|
|
Loading…
Reference in New Issue