release--苹果支付优化代码结构

release-2024-04-25
wangqing 2 months ago
parent a4c62623eb
commit 3831468f2c

@ -9,6 +9,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -33,9 +34,12 @@ import java.security.cert.X509Certificate;
@RequestMapping("applePay")
public class ApplePayController {
//购买凭证验证地址
private static final String certificateUrl = "https://buy.itunes.apple.com/verifyReceipt";
@Value("${applePay.certificate}")
private String certificateUrl;
// private static final String certificateUrl = "https://buy.itunes.apple.com/verifyReceipt";
//测试的购买凭证验证地址
private static final String certificateUrlTest = "https://sandbox.itunes.apple.com/verifyReceipt";
// private static final String certificateUrlTest = "https://sandbox.itunes.apple.com/verifyReceipt";
/**
* X509TrustManager
*/
@ -59,18 +63,17 @@ public class ApplePayController {
* @param chooseEnv falsetrue
*/
@PostMapping("/setIapCertificate")
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户Id"), @ApiImplicitParam(name = "receipt", value = "苹果传递前端支付成功的值"), @ApiImplicitParam(name = "chooseEnv", value = "是否是真实环境,布尔值")})
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户Id"), @ApiImplicitParam(name = "receipt", value = "苹果传递前端支付成功的值")})
@ResponseBody
public String setIapCertificate(String userId, String receipt, boolean chooseEnv) {
public String setIapCertificate(String userId, String receipt) {
// log.info("IOS端发送的购买凭证。数据有 userId = {},receipt = {},chooseEnv = {}",userId,receipt,chooseEnv);
if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(receipt)) {
return "后台发送道具失败用户ID 或者 receipt为空";
}
String url = null;
url = chooseEnv == true ? certificateUrl : certificateUrlTest;
final String certificateCode = receipt;
if (StringUtils.isNotEmpty(certificateCode)) {
String s = sendHttpsCoon(url, certificateCode, userId);
String s = sendHttpsCoon(certificateUrl, certificateCode, userId);
if ("支付成功".equals(s)) {
return "后台发送道具成功了,返回值按需自定义即可";
} else {

@ -54,4 +54,6 @@ wx:
# publicKeyPath: /home/wxcert/pub_key.pem
publicKeyPath: D:\pub_key.pem
publicKeyId: PUB_KEY_ID_0116763892292024111200648800000198
applePay:
certificate: https://sandbox.itunes.apple.com/verifyReceipt

Loading…
Cancel
Save