v1.0:调整谷歌支付代码

This commit is contained in:
2022-10-08 15:38:11 +08:00
parent 5dc2dad144
commit ef73c3bad2
5 changed files with 23 additions and 23 deletions

View File

@@ -24,7 +24,7 @@ import java.util.List;
* Helper class to initialize the publisher APIs client library.
* <p>
* Before making any calls to the API through the client library you need to
* call the {@link AndroidPublisherHelper#init(String, String, String, String)} method. This will run
* call the {@link #init(String, String)} method. This will run
* all precondition checks for for client id and secret setup properly in
* resources/client_secrets.json and authorize this client against the API.
* </p>
@@ -46,7 +46,7 @@ public class AndroidPublisherHelper {
private static volatile String oldCredentialJson;
public static AndroidPublisher init(String applicationName, String json) throws IOException, GeneralSecurityException {
public static void init(String applicationName, String json) throws IOException, GeneralSecurityException {
if (needInit(applicationName, json)) {
synchronized (AndroidPublisherHelper.class) {
if (needInit(applicationName, json) || androidPublisher == null) {
@@ -72,8 +72,6 @@ public class AndroidPublisherHelper {
}
}
}
return androidPublisher;
}
/**

View File

@@ -10,7 +10,7 @@ import com.accompany.core.model.Users;
import com.accompany.core.service.SysConfService;
import com.accompany.core.service.user.UsersBaseService;
import com.accompany.payment.dto.AppInnerPayRecordDTO;
import com.accompany.payment.dto.GooglePayLimitConfigDTO;
import com.accompany.payment.google.dto.GooglePayLimitConfigDTO;
import com.accompany.payment.model.ChargeProd;
import com.accompany.payment.model.ChargeRecord;
import com.accompany.payment.service.ChargeProdService;
@@ -56,28 +56,28 @@ public class GooglePlayBillingService {
try {
lock.tryLock(10, TimeUnit.SECONDS);
Users users = usersBaseService.getUsersByUid(uid);
if (users == null) {
log.error("充值用户不存在uId: {} ", uid);
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
ChargeProd chargeProd = chargeProdService.getChargeProdById(chargeProdId);
if (chargeProd == null) {
log.error("充值产品不存在prodId: {} ", chargeProdId);
throw new ServiceException(BusiStatus.CHARGE_PROD_NOT_EXIST);
}
String payChannel = getPayChannel();
log.info("用户 {} 内购充值,渠道: {}", uid, payChannel);
//保存充值记录
//1.创建订单号
//UUID不会重复所以不需要判断是否生成重复的订单号
String chargeRecordId = UUIDUitl.get();
Users users = usersBaseService.getUsersByUid(uid);
//Integer region = users.getRegion() == null ? Constant.region.overseas : users.getRegion();
ChargeRecord chargeRecord = new ChargeRecord();
chargeRecord.setChargeRecordId(chargeRecordId);
chargeRecord.setChargeProdId(chargeProdId);
chargeRecord.setUid(uid);
//chargeRecord.setRegion(region.byteValue());
chargeRecord.setChannel(payChannel);
chargeRecord.setChannel(Constant.ChargeChannel.google_play_billing);
chargeRecord.setChargeStatus(Constant.ChargeRecordStatus.create);
// product中money单位为分
chargeRecord.setAmount(chargeProd.getMoney());

View File

@@ -1,5 +1,6 @@
package com.accompany.payment.config;
package com.accompany.payment.google.config;
import com.accompany.core.base.SpringContextHolder;
import com.accompany.payment.google.AndroidPublisherHelper;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.exception.NacosException;
@@ -16,15 +17,17 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.List;
@Configuration
@Component
@Order(-1)
@Lazy(false)
@ConfigurationProperties(prefix = "google-play")
@@ -38,12 +41,11 @@ public class GooglePlayConfig {
private static final String CONFIG_NAME_APPLICATIONNAME = "google-play.applicationName";
private static final String CONFIG_NAME_JSON = "google-play.credentialJson";
@Autowired
private ConfigurableApplicationContext applicationContext;
@Bean("androidPublisher")
public AndroidPublisher initAndroidPublisher() throws IOException, GeneralSecurityException {
return AndroidPublisherHelper.init(applicationName, credentialJson);
@PostConstruct
@Async
public void initAndroidPublisherHelper() throws GeneralSecurityException, IOException {
AndroidPublisherHelper.init(applicationName, credentialJson);
}
/**
@@ -62,8 +64,9 @@ public class GooglePlayConfig {
}
}
if (needReInit) {
String application = applicationContext.getEnvironment().getProperty(CONFIG_NAME_APPLICATIONNAME);
String json = applicationContext.getEnvironment().getProperty(CONFIG_NAME_JSON);
Environment env = SpringContextHolder.getApplicationContext().getEnvironment();
String application = env.getProperty(CONFIG_NAME_APPLICATIONNAME);
String json = env.getProperty(CONFIG_NAME_JSON);
AndroidPublisherHelper.init(application, json);
}