|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.luoo.user.pojo.AppleOrder;
|
|
|
|
|
import com.luoo.user.pojo.AppleResponse;
|
|
|
|
|
import com.luoo.user.service.MemberShipService;
|
|
|
|
|
import com.luoo.user.util.IosVerifyUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -17,23 +19,19 @@ import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sendHttpsCoon 方法里面包含了增加的业务逻辑
|
|
|
|
|
* 本类引入多种的Json序列化工具,选择了Hutool
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Controller
|
|
|
|
|
@Api(tags = "苹果支付")
|
|
|
|
|
@RequestMapping("applePay")
|
|
|
|
|
public class ApplePayController {
|
|
|
|
|
//购买凭证验证地址
|
|
|
|
@ -56,9 +54,11 @@ public class ApplePayController {
|
|
|
|
|
public X509Certificate[] getAcceptedIssuers() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
|
|
}
|
|
|
|
@ -69,31 +69,31 @@ public class ApplePayController {
|
|
|
|
|
/**
|
|
|
|
|
* 接收自己APP客户端发过来的购买凭证
|
|
|
|
|
*
|
|
|
|
|
* @param userId 用户ID
|
|
|
|
|
* @param receipt 前端支付成功后:苹果给前端的一长串字符串
|
|
|
|
|
*
|
|
|
|
|
* @param userId 用户ID
|
|
|
|
|
* @param receipt 前端支付成功后:苹果给前端的一长串字符串
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/setIapCertificate")
|
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户Id"), @ApiImplicitParam(name = "receipt", value = "苹果传递前端支付成功的值")})
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public String setIapCertificate(String userId, String receipt) {
|
|
|
|
|
public Result<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为空";
|
|
|
|
|
return Result.failed("后台发送道具失败,用户ID 或者 receipt为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final String certificateCode = receipt;
|
|
|
|
|
if (StringUtils.isNotEmpty(certificateCode)) {
|
|
|
|
|
String s = sendHttpsCoon(certificateUrl, certificateCode, userId);
|
|
|
|
|
if ("支付成功".equals(s)) {
|
|
|
|
|
return "后台发送道具成功了,返回值按需自定义即可";
|
|
|
|
|
return Result.success("后台发送道具成功了,返回值按需自定义即可");
|
|
|
|
|
} else {
|
|
|
|
|
return "后台发送道具失败了!";
|
|
|
|
|
return Result.failed("后台发送道具失败了!");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return "后台发送道具失败!传参receipt 为空!";
|
|
|
|
|
return Result.failed("后台发送道具失败!传参receipt 为空!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 苹果沙箱账号密码:Xunliaoceshi002
|
|
|
|
|
* 发送请求 向苹果校验支付请求是否有效:本方法由认证方法进行调用
|
|
|
|
@ -108,9 +108,9 @@ public class ApplePayController {
|
|
|
|
|
}
|
|
|
|
|
String line = null;
|
|
|
|
|
|
|
|
|
|
String result = iosVerifyUtil.buyAppVerify(receipt, 1);
|
|
|
|
|
String result = iosVerifyUtil.buyAppVerify(receipt, 1);
|
|
|
|
|
|
|
|
|
|
System.out.println(result+"");
|
|
|
|
|
System.out.println(result + "");
|
|
|
|
|
// todo 理论应该锁UserId,因为后台只能允许一个线程执行给玩家发送道具!
|
|
|
|
|
try {
|
|
|
|
|
// // 设置SSLContext
|
|
|
|
@ -151,14 +151,14 @@ public class ApplePayController {
|
|
|
|
|
String transaction_id = appleOrder.getTransaction_id();
|
|
|
|
|
String original_purchase_date_ms = appleOrder.getOriginal_purchase_date_ms();
|
|
|
|
|
System.out.println(original_purchase_date_ms);
|
|
|
|
|
log.info("用户下单时间:{}",new DateTime(Long.valueOf(original_purchase_date_ms)+16*60*60*1000));
|
|
|
|
|
log.info("用户下单时间:{}", new DateTime(Long.valueOf(original_purchase_date_ms) + 16 * 60 * 60 * 1000));
|
|
|
|
|
// todo 校验订单号没有发放过道具
|
|
|
|
|
if (true) {
|
|
|
|
|
String quantity = appleOrder.getQuantity();
|
|
|
|
|
// 获取用户购买的产品Id,
|
|
|
|
|
String product_id = appleOrder.getProduct_id();
|
|
|
|
|
memberShipService.applePayMembershipOrder(product_id, userId);
|
|
|
|
|
log.info("{}发送奖励成功喽!",userId);
|
|
|
|
|
log.info("{}发送奖励成功喽!", userId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "支付成功";
|
|
|
|
@ -171,6 +171,7 @@ public class ApplePayController {
|
|
|
|
|
}
|
|
|
|
|
return "苹果回调处理失败!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注意:下面代码跟苹果支付业务无关。
|
|
|
|
|
* 这里的code 是前端请求苹果获取到的参数
|
|
|
|
|