|
|
|
@ -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 false代表苹果沙箱环境,true代表真实支付环境
|
|
|
|
|
*/
|
|
|
|
|
@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 {
|
|
|
|
|