release- apply pay 业务逻辑

release-2024-04-25
pikaqiudeshujia 2 months ago
parent 51b380824a
commit 8f3a056a14

@ -4,5 +4,5 @@ spring:
name: eureka
profile: dev
label: master
uri: http://116.62.145.60:12000
# uri: http://127.0.0.1:12000
# uri: http://116.62.145.60:12000
uri: http://127.0.0.1:12000

@ -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
* JsonHutool
*/
@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

@ -3,6 +3,7 @@ package com.luoo.user.dao;
import com.luoo.user.pojo.MembershipOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface MembershipOrderDao extends JpaRepository<MembershipOrder, String>, JpaSpecificationExecutor<MembershipOrder> {
public interface MembershipOrderDao extends JpaRepository<MembershipOrder, String>, JpaSpecificationExecutor<MembershipOrder>, QuerydslPredicateExecutor<MembershipOrder> {
}

@ -11,7 +11,6 @@ import org.hibernate.annotations.Where;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
/**
* @program: luoo_parent
@ -40,4 +39,7 @@ public class VipSku extends JPABasePojo {
@ApiModelProperty(value = "价格,单位(分)")
private Integer amount;
@ApiModelProperty(value = "苹果产品id")
private String applyProductId;
}

@ -1,16 +1,12 @@
package com.luoo.user.service;
import api.Result;
import com.ijpay.core.kit.WxPayKit;
import com.luoo.user.config.WxPayConfig;
import com.luoo.user.config.WxPayPublicKeyConfig;
import com.luoo.user.dao.MembershipOrderDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dao.VipSkuDao;
import com.luoo.user.pojo.MembershipOrder;
import com.luoo.user.pojo.QMembershipOrder;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.pojo.VipSku;
import com.luoo.user.pojo.*;
import com.luoo.user.vo.membership.VipSkuVO;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.wechat.pay.java.service.payments.app.AppService;
@ -24,14 +20,11 @@ import enums.MembershipEnums;
import enums.PointEnums;
import enums.UserVipStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import util.JwtUtil;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
@ -95,6 +88,7 @@ public class MemberShipService {
.days(item.getDays())
.lifeFlag(item.getLifeFlag())
.amount(item.getAmount())
.applyProductId(item.getApplyProductId())
.build()).collect(Collectors.toList());
}
@ -209,7 +203,7 @@ public class MemberShipService {
/**
*
*
* @param type
* @param type id
* @param userId id
*/
@Transactional(rollbackFor = Exception.class)
@ -227,37 +221,15 @@ public class MemberShipService {
.status(MembershipEnums.PAY_SUCCESS.getCode())
.build();
String skuId = "";
switch (type) {
case "cn.luoo.IndieMusic.annual": {
// 年度会员 逻辑从这开始
System.out.println("appleIAP 年度会员 逻辑从这开始,userid___" + userId);
// todo 这边会员种类是写死的,最好苹果支付有个字段能对应,否则每次都要改代码后发布
skuId = "2";
//这里拿到userId,在我们自己的订单逻辑里插一条订单记录,给用户开通相应的会员
userId = "";
break;
}
case "cn.luoo.IndieMusic.monthly": {
// 月度会员逻辑从这开始
System.out.println("appleIAP 月度会员 逻辑从这开始,userid___" + userId);
;
skuId = "1";
break;
}
case "cn.luoo.IndieMusic.lifetime": {
// 终身会员逻辑从这开始
System.out.println("appleIAP 终身会员 逻辑从这开始,userid___" + userId);
skuId = "3";
break;
}
}
QVipSku qVipSku = QVipSku.vipSku;
VipSku vipSku = jpaQueryFactory.selectFrom(qVipSku)
.where(qVipSku.applyProductId.eq(type))
.fetchOne();
if (StringUtils.isNotBlank(skuId)) {
if (vipSku != null) {
membershipOrder.setSkuId(vipSku.getId());
membershipOrder.setId(String.valueOf(idWorker.nextId()));
membershipOrder.setSkuId(skuId);
VipSku vipSku = vipSkuDao.getOne(skuId);
membershipOrder.setSkuId(vipSku.getId());
membershipOrder.setAmount(vipSku.getAmount());
membershipOrder.setLife(vipSku.getLifeFlag());
membershipOrder.setDuration(vipSku.getDays());

@ -7,7 +7,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @program: luoo_parent
@ -33,4 +32,7 @@ public class VipSkuVO implements Serializable {
@ApiModelProperty(value = "价格,单位(分)")
private Integer amount;
@ApiModelProperty(value = "苹果产品id")
private String applyProductId;
}

Loading…
Cancel
Save