Browse Source

提现的一大堆功能

master
nili 7 months ago
parent
commit
c80fdb7647
  1. 9
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixApp.java
  2. 21
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixMoneyRecord.java
  3. 2
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixUser.java
  4. 30
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMoneyRecordMapper.java
  5. 7
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixUserMapper.java
  6. 39
      game-service/src/main/java/awesome/group/game/service/ScheduleService.java
  7. 125
      game-service/src/main/java/awesome/group/game/service/UMengService.java
  8. 40
      game-service/src/main/java/awesome/group/game/service/bo/citrus/AppBo.java
  9. 18
      game-service/src/main/java/awesome/group/game/service/bo/citrus/CashRecord.java
  10. 1
      game-service/src/main/java/awesome/group/game/service/bo/citrus/LoginReq.java
  11. 2
      game-service/src/main/java/awesome/group/game/service/bo/citrus/UserBo.java
  12. 9
      game-service/src/main/java/awesome/group/game/service/bo/matrix/AliPayConfigBo.java
  13. 8
      game-service/src/main/java/awesome/group/game/service/bo/matrix/UmengConfigBo.java
  14. 6
      game-service/src/main/java/awesome/group/game/service/bo/matrix/WxConfigBo.java
  15. 18
      game-service/src/main/java/awesome/group/game/service/citrus/CitrusAppService.java
  16. 88
      game-service/src/main/java/awesome/group/game/service/citrus/UserService.java
  17. 114
      game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java
  18. 2
      game-service/src/test/java/awesome/group/game/ServiceTestApplication.java
  19. 18
      game-service/src/test/java/awesome/group/game/service/UMengServiceTest.java
  20. 198
      game-service/src/test/java/awesome/group/game/service/pay/AlipayFundTransUniTransferTest.java
  21. 9
      game-web/src/main/java/awesome/group/game/web/filter/CitrusLoginFilter.java
  22. 24
      game-web/src/main/java/awesome/group/game/web/rest/citrus/CitrusAppController.java
  23. 8
      game-web/src/main/java/awesome/group/game/web/rest/citrus/OpenController.java
  24. 27
      game-web/src/main/java/awesome/group/game/web/rest/citrus/UserController.java

9
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixApp.java

@ -16,4 +16,13 @@ public class MatrixApp {
private String channel;
private Integer hide;
private String secret;
private String umeng;//友盟的配置数据
private String aliPay;//支付宝的配置数据
private String wx;//微信的配置数据
private String moneyLadder;
private Integer noAuditMoney;
private String qqUrl;
private Integer dayLimit;//每日提现次数限制
}

21
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixMoneyRecord.java

@ -0,0 +1,21 @@
package awesome.group.game.dao.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class MatrixMoneyRecord {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Integer userId;
private Integer appId;
private Integer cent;
private String aliPayAccount;
private String name;
private String reason;
private Integer status;//0发起申请,1审批成功,2转账中,3转账成功,-1转账失败
private Timestamp createdAt;
}

2
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixUser.java

@ -18,5 +18,5 @@ public class MatrixUser {
private String pwd;
private String inviteCode;
private Integer upUid;
private Long income;
private Long income;//分,累计收益
}

30
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixMoneyRecordMapper.java

@ -0,0 +1,30 @@
package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.sql.Timestamp;
import java.util.List;
public interface MatrixMoneyRecordMapper extends BaseMapper<MatrixMoneyRecord> {
@Select("select count(*) from matrix_money_record where status != -1 and user_id = #{userId} and created_at > #{timestamp}")
int queryAfter(Integer userId, Timestamp timestamp);
@Select("select count(*) from matrix_money_record where status != -1 and ali_pay_account = #{aliPayAccount} and created_at > #{timestamp}")
int queryByAliPayAccount(String aliPayAccount, Timestamp timestamp);
@Select("select * from matrix_money_record where status = #{status}")
List<MatrixMoneyRecord> queryByStatus(Integer status);
@Update("update matrix_money_record set status = #{status} where id = #{id} and status = #{prevStatus}")
int updateStatusWithPrev(int id, int prevStatus, int status);
@Update("update matrix_money_record set status = #{status}, reason=#{reason} where id = #{id}")
int updateStatusAndReason(int id, int status, String reason);
@Select("select * from matrix_money_record where user_id = #{userId}")
List<MatrixMoneyRecord> queryByUserId(Integer userId);
}

7
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixUserMapper.java

@ -3,6 +3,7 @@ package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
public interface MatrixUserMapper extends BaseMapper<MatrixUser> {
@ -11,4 +12,10 @@ public interface MatrixUserMapper extends BaseMapper<MatrixUser> {
@Select("select * from matrix_user where app_id = #{appId} and mobile = #{mobile}")
MatrixUser selectByAppIdAndMobile(int appId, String mobile);
@Update("update matrix_user set money = money + #{cent} where id = #{userId}")
int incMoney(int userId, int cent);
@Update("update matrix_user set ali_pay_account = #{aliPayAccount}, name = #{name} where id = #{userId}")
int updateAliPayAccount(int userId, String aliPayAccount, String name);
}

39
game-service/src/main/java/awesome/group/game/service/ScheduleService.java

@ -0,0 +1,39 @@
package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
import awesome.group.game.dao.mapper.MatrixMoneyRecordMapper;
import awesome.group.game.dao.mapper.MatrixUserMapper;
import awesome.group.game.service.citrus.UserService;
import awesome.group.game.service.pay.AlipayFundTransUniTransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ScheduleService {
@Autowired
private MatrixMoneyRecordMapper moneyRecordMapper;
@Autowired
private AlipayFundTransUniTransfer aliTransfer;
@Autowired
private MatrixUserMapper userMapper;
@Scheduled(cron = "0 0/1 * * * ?")
public void transfer() {
List<MatrixMoneyRecord> list = moneyRecordMapper.queryByStatus(UserService.STATUS_AUDIT_PASS);
for (MatrixMoneyRecord r : list) {
int rows = moneyRecordMapper.updateStatusWithPrev(r.getId(), UserService.STATUS_AUDIT_PASS, UserService.STATUS_TRANSFERRING);
if (rows < 1) {
continue;
}
boolean success = aliTransfer.transfer(r);
moneyRecordMapper.updateStatusAndReason(r.getId(), r.getStatus(), r.getReason());
if (!success) {
userMapper.incMoney(r.getUserId(), -r.getCent());
}
}
}
}

125
game-service/src/main/java/awesome/group/game/service/UMengService.java

@ -0,0 +1,125 @@
package awesome.group.game.service;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
import awesome.group.game.service.common.log.L;
import com.google.gson.Gson;
import okhttp3.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Service
public class UMengService {
public static final String APP_KEY = "24785365";//阿里云
public static final String APP_SECRET = "7e3a9e8ae85cd8c1ff58343e241ec154";
public static final String APP_CODE = "2c62d2208aa640f09a55449efa634424";
public static final String APP_KEY_UMENT = "66403e5dcac2a664de3234d4";//友盟
public static final String API_PREFIX = "https://verify5.market.alicloudapi.com";
public static Gson gson = new Gson();
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private final OkHttpClient httpClient = new OkHttpClient().newBuilder().connectTimeout(2, TimeUnit.SECONDS).readTimeout(5, TimeUnit.SECONDS).connectionPool(new ConnectionPool(8, 5, TimeUnit.MINUTES)).build();
public String getMobile(String token) {
Map<String, Object> data = new HashMap<>();
data.put("token", token);
String api = "/api/v1/mobile/info?appkey=" + APP_KEY_UMENT;
String res = doHttpPost(api, data);
System.out.println(res);
return res;
}
public String doHttpPost(String url, Map<String, Object> jsonBody) {
Map<String, String> header = new HashMap<>();
String body = gson.toJson(jsonBody);
header.put("Content-Type", "application/json; charset=utf-8");
header.put("Accept", "application/json");
header.put("X-Ca-Version", "1");
header.put("X-Ca-Signature-Headers", "X-Ca-Version,X-Ca-Stage,X-Ca-Key,X-Ca-Timestamp");
header.put("X-Ca-Stage", "RELEASE");
header.put("X-Ca-Key", APP_KEY);
header.put("X-Ca-Timestamp", String.valueOf(System.currentTimeMillis()));
header.put("X-Ca-Nonce", UUID.randomUUID().toString());
header.put("Content-MD5", Base64.encodeBase64String(DigestUtils.md5(body.getBytes())));
/**
* sign
*/
String stringToSign = getSignString(header, "POST", url);
try {
Mac hmacSha256 = Mac.getInstance("HmacSHA256");
byte[] keyBytes = APP_SECRET.getBytes(StandardCharsets.UTF_8);
hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA256"));
String sign = new String(Base64.encodeBase64(hmacSha256.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8))));
header.put("X-Ca-Signature", sign);
return postJson(url, jsonBody, header);
} catch (InvalidKeyException | NoSuchAlgorithmException e) {
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "验证失败,请重试");
}
}
private static String getSignString(Map<String, String> header, String method, String url) {
return method.toUpperCase() + "\n" +
header.get("Accept") + "\n" +
header.get("Content-MD5") + "\n" +
header.get("Content-Type") + "\n\n" +
"X-Ca-Key:" + header.get("X-Ca-Key") + "\n" +
"X-Ca-Stage:" + header.get("X-Ca-Stage") + "\n" +
"X-Ca-Timestamp:" + header.get("X-Ca-Timestamp") + "\n" +
"X-Ca-Version:" + header.get("X-Ca-Version") + "\n" +
url;
}
private String postJson(String url, Map<String, Object> body, Map<String, String> headers) {
String bodyStr = gson.toJson(body);
RequestBody requestBody = RequestBody.create(JSON, bodyStr);
if (!url.startsWith("http")) {
url = API_PREFIX + url;
}
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
Request.Builder requestBuilder = new Request.Builder().post(requestBody).url(urlBuilder.build());
if (!CollectionUtils.isEmpty(headers)) {
headers.forEach(requestBuilder::addHeader);
}
Request request = requestBuilder.build();
String msg = "url:" + url + ",header:" + gson.toJson(headers) + ", body:" + bodyStr;
return doHttpExecute(msg, request);
}
private String doHttpExecute(String msg, Request request) {
try (Response resp = httpClient.newCall(request).execute()) {
if (!resp.isSuccessful() || resp.body() == null) {
L.trace("request_umeng_error", msg + ",resp:" + resp);
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "友盟请求失败");
}
return Objects.requireNonNull(resp.body()).string();
} catch (IOException ioe) {
L.trace("request_umeng_error", msg, ioe);
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, ioe.getMessage(), ioe);
}
}
}

40
game-service/src/main/java/awesome/group/game/service/bo/citrus/AppBo.java

@ -0,0 +1,40 @@
package awesome.group.game.service.bo.citrus;
import awesome.group.game.dao.bean.MatrixApp;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.List;
public class AppBo {
public List<Integer> moneyLadder;//提现梯度,单位分
public Integer noAuditMoney;//不需审核的金额,单位分
public String qqUrl;//qq客服链接
public Integer dayLimit;//每日提现次数
public AppBo() {
}
public AppBo(MatrixApp app) {
Gson gson = new Gson();
if (StringUtils.hasText(app.getMoneyLadder())) {
this.moneyLadder = gson.fromJson(app.getMoneyLadder(), new TypeToken<List<Long>>() {
}.getType());
} else {
moneyLadder = Arrays.asList(30, 50, 100, 10000, 30000, 50000);
}
if (app.getNoAuditMoney() != null) {
this.noAuditMoney = app.getNoAuditMoney();
} else {
this.noAuditMoney = 30;
}
this.qqUrl = app.getQqUrl();
if (app.getDayLimit() != null) {
this.dayLimit = app.getDayLimit();
} else {
this.dayLimit = 3;
}
}
}

18
game-service/src/main/java/awesome/group/game/service/bo/citrus/CashRecord.java

@ -0,0 +1,18 @@
package awesome.group.game.service.bo.citrus;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
public class CashRecord {
public Integer cent;//提现金额,分
public Long createTime;//提现时间,时间戳, 毫秒
public Integer status;//0发起申请,1审批成功,2转账中,3转账成功,-1转账失败
public CashRecord() {
}
public CashRecord(MatrixMoneyRecord r) {
this.cent = r.getCent();
this.createTime = r.getCreatedAt().getTime();
this.status = r.getStatus();
}
}

1
game-service/src/main/java/awesome/group/game/service/bo/citrus/LoginReq.java

@ -5,5 +5,6 @@ public class LoginReq {
public String pwd;
public String appCode;
public String code;//验证码
public String token;//友盟token
}

2
game-service/src/main/java/awesome/group/game/service/bo/citrus/UserBo.java

@ -11,6 +11,7 @@ public class UserBo {
public Integer money;//分,已提现金额
public String aliPayAccount;
public Long income;//ecpm和,分
public Long goldCoin;//金币
public String inviteCode;
public String inviteUrl;
@ -28,5 +29,6 @@ public class UserBo {
this.nickname = u.getNickname();
this.avatar = u.getAvatar();
this.money = u.getMoney();
this.goldCoin = u.getIncome() - (u.getMoney() * 1000);
}
}

9
game-service/src/main/java/awesome/group/game/service/bo/matrix/AliPayConfigBo.java

@ -0,0 +1,9 @@
package awesome.group.game.service.bo.matrix;
public class AliPayConfigBo {
public String aliPayPublicCert;
public String aliPayRootCert;
public String aliPayAppCert;
public String aliPayPrivateKey;
public String aliPayAppId;
}

8
game-service/src/main/java/awesome/group/game/service/bo/matrix/UmengConfigBo.java

@ -0,0 +1,8 @@
package awesome.group.game.service.bo.matrix;
public class UmengConfigBo {
public String umengAppKeyAli;
public String umengAppSecret;
public String umengAppCode;
public String umengAppKey;
}

6
game-service/src/main/java/awesome/group/game/service/bo/matrix/WxConfigBo.java

@ -0,0 +1,6 @@
package awesome.group.game.service.bo.matrix;
public class WxConfigBo {
public String wxAppId;
public String wxAppSecret;
}

18
game-service/src/main/java/awesome/group/game/service/citrus/CitrusAppService.java

@ -0,0 +1,18 @@
package awesome.group.game.service.citrus;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.citrus.AppBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CitrusAppService {
@Autowired
private MatrixAppMapper appMapper;
public AppBo getAppDetail(String appCode) {
MatrixApp app = appMapper.queryByCode(appCode);
return new AppBo(app);
}
}

88
game-service/src/main/java/awesome/group/game/service/citrus/UserService.java

@ -1,20 +1,32 @@
package awesome.group.game.service.citrus;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
import awesome.group.game.dao.bean.MatrixUser;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.dao.mapper.MatrixMoneyRecordMapper;
import awesome.group.game.dao.mapper.MatrixUserMapper;
import awesome.group.game.service.SmsService;
import awesome.group.game.service.bo.citrus.AppBo;
import awesome.group.game.service.bo.citrus.CashRecord;
import awesome.group.game.service.bo.citrus.LoginReq;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
import awesome.group.game.service.util.DateUtil;
import awesome.group.game.service.util.EncryptUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.List;
@Service
public class UserService {
@Autowired
@ -26,6 +38,22 @@ public class UserService {
@Autowired
private SmsService smsService;
@Autowired
private MatrixMoneyRecordMapper moneyRecordMapper;
@Lazy
@Autowired
private UserService userService;
public static final int STATUS_WAITING = 0;//等审核
public static final int STATUS_AUDIT_PASS = 1;//已审核通过
public static final int STATUS_TRANSFERRING = 2;//转账中
public static final int TRANSFER_SUCCESS = 3;
public static final int TRANSFER_FAIL = -1;
public MatrixUser login(LoginReq req) {
Assert.isTrue(req != null, "非法请求");
Assert.isTrue(StringUtils.hasText(req.mobile), "非法请求");
@ -56,8 +84,68 @@ public class UserService {
return user;
}
public MatrixUser loginByToken(String appCode, String token) {
Assert.isTrue(StringUtils.hasText(appCode), "非法请求");
Assert.isTrue(StringUtils.hasText(token), "非法请求");
MatrixApp app = appMapper.queryByCode(appCode);
Assert.isTrue(app != null, "非法请求");
LambdaQueryWrapper<MatrixUser> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MatrixUser::getAppId, app.getId());
return userMapper.selectOne(wrapper);
}
public UserBo getUser(Integer uid) {
MatrixUser u = userMapper.selectById(uid);
return new UserBo(u);
}
public void bindAliPay(Integer uid, String name, String aliPayAccount) {
Assert.isTrue(StringUtils.hasText(aliPayAccount), "支付宝账号不能为空");
Assert.isTrue(StringUtils.hasText(name), "支付宝账号姓名不能为空");
MatrixUser u = userMapper.selectById(uid);
Assert.isTrue(u != null, "非法请求");
userMapper.updateAliPayAccount(uid, aliPayAccount, name);
}
public List<CashRecord> getCashRecord(Integer uid) {
List<MatrixMoneyRecord> list = moneyRecordMapper.queryByUserId(uid);
return list.stream().map(CashRecord::new).toList();
}
public void applyMoney(Integer uid, Integer cent) {
Assert.isTrue(cent >= 10, "至少提0.1元");
MatrixUser u = userMapper.selectById(uid);
Assert.isTrue(u != null, "非法请求");
Assert.isTrue(u.getMoney() + cent <= u.getIncome(), "余额不足");
String aliPayAccount = u.getAliPayAccount();
Assert.isTrue(StringUtils.hasText(aliPayAccount), "请先绑定支付宝账号");
Assert.isTrue(StringUtils.hasText(u.getName()), "请先填写支付宝实名姓名");
MatrixApp app = appMapper.selectById(u.getAppId());
AppBo appBo = new AppBo(app);
Assert.isTrue(appBo.moneyLadder.contains(cent), "提现金额不合法");
Timestamp todayBegin = new Timestamp(DateUtil.getDayBeginTimestamp(System.currentTimeMillis()));
int size = moneyRecordMapper.queryAfter(uid, todayBegin);
Assert.isTrue(size < appBo.dayLimit, "每天最多提现" + appBo.dayLimit + "次");
size = moneyRecordMapper.queryByAliPayAccount(aliPayAccount, todayBegin);
Assert.isTrue(size < appBo.dayLimit, "每天最多提现" + appBo.dayLimit + "次");
userService.doApply(u, app.getNoAuditMoney(), cent);
}
@Transactional
public void doApply(MatrixUser u, Integer noAuditMoney, Integer cent) {
int uid = u.getId();
MatrixMoneyRecord record = new MatrixMoneyRecord();
record.setUserId(uid);
record.setAppId(u.getAppId());
record.setCent(cent);
record.setAliPayAccount(u.getAliPayAccount());
record.setName(u.getName());
record.setStatus(cent <= noAuditMoney ? STATUS_AUDIT_PASS : STATUS_WAITING);
userMapper.incMoney(uid, cent);
u = userMapper.selectById(uid);
Assert.isTrue(u.getMoney() <= u.getIncome(), "余额不足");
moneyRecordMapper.insert(record);
}
}

114
game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java

@ -0,0 +1,114 @@
package awesome.group.game.service.pay;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.matrix.AliPayConfigBo;
import awesome.group.game.service.citrus.UserService;
import awesome.group.game.service.common.log.L;
import awesome.group.game.service.util.DateUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.google.gson.Gson;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class AlipayFundTransUniTransfer {
@Autowired
private MatrixAppMapper appMapper;
private Map<Integer, AlipayClient> appPayClientMap = new HashMap<>();
private Gson gson = new Gson();
@PostConstruct
public void init() {
List<MatrixApp> appList = appMapper.selectList(null);
for (MatrixApp app : appList) {
if (StringUtils.hasText(app.getAliPay())) {
AliPayConfigBo configBo = gson.fromJson(app.getAliPay(), AliPayConfigBo.class);
CertAlipayRequest alipayConfig = getAlipayConfig(configBo);
try {
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
appPayClientMap.put(app.getId(), alipayClient);
} catch (AlipayApiException e) {
L.trace("initAliPayClientError", "app:" + gson.toJson(app), e);
}
}
}
}
//文档:https://opendocs.alipay.com/open/309/106236?pathHash=97724ae4#%E8%BD%AC%E8%B4%A6%E5%92%8C%E9%80%9A%E7%9F%A5
public boolean transfer(MatrixMoneyRecord record) {
AlipayClient alipayClient = appPayClientMap.get(record.getAppId());
if (alipayClient == null) {
L.trace("transferError", "app:" + record.getAppId() + "提现未开启或配置错误");
return false;
}
MatrixApp app = appMapper.selectById(record.getAppId());
try {
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
model.setOrderTitle(app.getName() + "-提现");
model.setBizScene("DIRECT_TRANSFER");
model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
model.setRemark(app.getName() + "-提现");
String orderNo = String.format("%08d", record.getId());
model.setOutBizNo(DateUtil.currentDate() + orderNo);//最小可传金额 0.1 元,
model.setTransAmount(String.format("%.2f", record.getCent() / 100.0));
model.setProductCode("TRANS_ACCOUNT_NO_PWD");
Participant payeeInfo = new Participant();
payeeInfo.setIdentity(record.getAliPayAccount());
payeeInfo.setName(record.getName());
payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
model.setPayeeInfo(payeeInfo);
request.setBizModel(model);
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
if (response.isSuccess()) {
record.setStatus(UserService.TRANSFER_SUCCESS);
return true;
} else {
record.setStatus(UserService.TRANSFER_FAIL);
String reason = response.getCode() + "," + response.getMsg();
record.setReason(reason);
return false;
}
} catch (AlipayApiException e) {
L.trace("transferError", "record:" + gson.toJson(record), e);
record.setReason("转账失败");
record.setStatus(UserService.TRANSFER_FAIL);
return false;
}
}
private static CertAlipayRequest getAlipayConfig(AliPayConfigBo bo) {
String privateKey = bo.aliPayPrivateKey;
CertAlipayRequest alipayConfig = new CertAlipayRequest();
alipayConfig.setPrivateKey(privateKey);
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
alipayConfig.setAppId(bo.aliPayAppId);
alipayConfig.setCharset("UTF-8");
alipayConfig.setSignType("RSA2");
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicCertContent(bo.aliPayPublicCert);
alipayConfig.setCertContent(bo.aliPayAppCert);
alipayConfig.setRootCertContent(bo.aliPayRootCert);
return alipayConfig;
}
}

2
game-service/src/test/java/awesome/group/game/ServiceTestApplication.java

@ -2,11 +2,13 @@ package awesome.group.game;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author nidaren
*/
@SpringBootApplication
@EnableScheduling
public class ServiceTestApplication {
public static void main(String[] args) throws Exception {

18
game-service/src/test/java/awesome/group/game/service/UMengServiceTest.java

@ -0,0 +1,18 @@
package awesome.group.game.service;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.jupiter.api.Assertions.*;
class UMengServiceTest extends BaseTest{
@Autowired
private UMengService uMengService;
@Test
void getMobile() {
String token = "eyJjIjoiNmk5amtxSVwvNXhXRElTRkNIeUpcL1RTemNjTEJsOEtiWndkT0NEYlhkUFJQREUzZ3g1bWx1bmNYdzRtclBWODVYOEludnJzS1pTOTRRXG53ejRudVlSaUs4cTFtRUdcL2FPQ0tIRktiUUtuS2Iya0ZFWjlyNWpPV044R0w3Q2I3V1g5dDA0ays2dmJwUXpaNGVTMklyOTJJcGtqaVxudm0rVG5vWVVVZWl4ZHhNNDArZ0hla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GNpdUZubWlzYmlXUmpmdz09IiwibyI6IkFuZHJvaWQifQ==";
uMengService.getMobile(token);
}
}

198
game-service/src/test/java/awesome/group/game/service/pay/AlipayFundTransUniTransferTest.java

@ -0,0 +1,198 @@
package awesome.group.game.service.pay;
import awesome.group.game.dao.bean.MatrixMoneyRecord;
import awesome.group.game.service.BaseTest;
import awesome.group.game.service.bo.matrix.AliPayConfigBo;
import awesome.group.game.service.citrus.UserService;
import com.alipay.api.AlipayApiException;
import com.google.gson.Gson;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
class AlipayFundTransUniTransferTest extends BaseTest {
@Autowired
private AlipayFundTransUniTransfer alipayFundTransUniTransfer;
@Autowired
private UserService userService;
@Test
void test1() throws AlipayApiException {
MatrixMoneyRecord matrixMoneyRecord = new MatrixMoneyRecord();
matrixMoneyRecord.setAppId(6);
matrixMoneyRecord.setAliPayAccount("19181749767");
matrixMoneyRecord.setName("倪丽");
matrixMoneyRecord.setCent(10);
alipayFundTransUniTransfer.transfer(matrixMoneyRecord);
}
@Test
public void testApply() {
userService.applyMoney(3, 10);
}
@Test
public void genGson() {
AliPayConfigBo bo = new AliPayConfigBo();
bo.aliPayAppId = "2021004143647533";
bo.aliPayPrivateKey = "MIIEuwIBADANBgkqhkiG9w0BAQEFAASCBKUwggShAgEAAoIBAQCeU75wMTR1FUEbptIFgk9/aR+lPgMWVsONuj1JnRADqz/3AiNvDiXm20V75aZ/mUf+LaPx2su3wn2JoVr5reIOvx797Tb9JiUn/ucBx5p0lcEQbkMEh+PzXAZK6miRS4thgLEWbfrcVV7TTvGvlKiBVVPPfOfEmaqd/qX0aen9bOJ6/HH8EnTb19yckTK9xNO4WK4SqD66Xr649KyRteeeqx62ClbIU04ZMbywlmvkF1sjQbMI7MHMfHDHuI+3SuxQHY6INZwvG8Fua/6c4xCpAijjO0PnOlm5aZ7CxxwaxQva/jfHAQ7mq5xuvs1pyvtkhDF6md/RIqgFXM+w1VHDAgMBAAECggEB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fVeUdQa29IZKrIDVj65THQIDAQABo2MwYTAf\n" +
"BgNVHSMEGDAWgBRfdLQEwE8HWurlsdsio4dBspzhATAdBgNVHQ4EFgQUSqHkYINtUSAtDPnS8Xoy\n" +
"oP9p7qEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQELBQADggIB\n" +
"AIQ8TzFy4bVIVb8+WhHKCkKNPcJe2EZuIcqvRoi727lZTJOfYy/JzLtckyZYfEI8J0lasZ29wkTt\n" +
"a1IjSo+a6XdhudU4ONVBrL70U8Kzntplw/6TBNbLFpp7taRALjUgbCOk4EoBMbeCL0GiYYsTS0mw\n" +
"7xdySzmGQku4GTyqutIGPQwKxSj9iSFw1FCZqr4VP4tyXzMUgc52SzagA6i7AyLedd3tbS6lnR5B\n" +
"L+W9Kx9hwT8L7WANAxQzv/jGldeuSLN8bsTxlOYlsdjmIGu/C9OWblPYGpjQQIRyvs4Cc/mNhrh+\n" +
"14EQgwuemIIFDLOgcD+iISoN8CqegelNcJndFw1PDN6LkVoiHz9p7jzsge8RKay/QW6C03KNDpWZ\n" +
"EUCgCUdfHfo8xKeR+LL1cfn24HKJmZt8L/aeRZwZ1jwePXFRVtiXELvgJuM/tJDIFj2KD337iV64\n" +
"fWcKQ/ydDVGqfDZAdcU4hQdsrPWENwPTQPfVPq2NNLMyIH9+WKx9Ed6/WzeZmIy5ZWpX1TtTolo6\n" +
"OJXQFeItMAjHxW/ZSZTok5IS3FuRhExturaInnzjYpx50a6kS34c5+c8hYq7sAtZ/CNLZmBnBCFD\n" +
"aMQqT8xFZJ5uolUaSeXxg7JFY1QsYp5RKvj4SjFwCGKJ2+hPPe9UyyltxOidNtxjaknOCeBHytOr\n" +
"-----END CERTIFICATE-----\n";
Gson gson = new Gson();
String json = gson.toJson(bo);
System.out.println(json);
}
}

9
game-web/src/main/java/awesome/group/game/web/filter/CitrusLoginFilter.java

@ -32,14 +32,7 @@ public class CitrusLoginFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String token = "";
if(httpRequest.getCookies() != null) {
for (Cookie c : httpRequest.getCookies()) {
if (c.getName().equals("CitrusToken")) {
token = c.getValue();
}
}
}
String token = httpRequest.getHeader("Authorization");
List<String> openApi = List.of(
"/api/citrus/register",
"/api/citrus/login"

24
game-web/src/main/java/awesome/group/game/web/rest/citrus/CitrusAppController.java

@ -0,0 +1,24 @@
package awesome.group.game.web.rest.citrus;
import awesome.group.game.service.bo.citrus.AppBo;
import awesome.group.game.service.citrus.CitrusAppService;
import awesome.group.game.service.common.response.R;
import awesome.group.game.web.aop.RestApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/citrus/app")
public class CitrusAppController {
@Autowired
private CitrusAppService appService;
@GetMapping("/getDetail")
@RestApi
public R<AppBo> getAppDetail(@RequestParam String appCode) {
return new R<>(appService.getAppDetail(appCode));
}
}

8
game-web/src/main/java/awesome/group/game/web/rest/citrus/OpenController.java

@ -75,4 +75,12 @@ public class OpenController {
return new R<>(R.CODE_SUCCESS, "ok", token);
}
@PostMapping("/loginByToken")
@RestApi
public R<String> loginByToken(@RequestBody LoginReq req) {
MatrixUser u = userService.loginByToken(req.appCode, req.token);
String token = JwtUtils.generatorToken(u.getId() + "", 15 * 86400);
return new R<>(R.CODE_SUCCESS, "ok", token);
}
}

27
game-web/src/main/java/awesome/group/game/web/rest/citrus/UserController.java

@ -1,14 +1,15 @@
package awesome.group.game.web.rest.citrus;
import awesome.group.game.service.bo.citrus.CashRecord;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.citrus.UserService;
import awesome.group.game.service.common.response.R;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/citrus/user")
@ -22,4 +23,24 @@ public class UserController {
public R<UserBo> currentUser() {
return new R<>(userService.getUser(RequestContext.getCitrusUid()));
}
@PostMapping("/bindAliPay")
@RestApi
public R<Void> bindAliPay(@RequestBody UserBo userBo) {
userService.bindAliPay(RequestContext.getCitrusUid(), userBo.aliPayAccount, userBo.name);
return new R<>(null);
}
@GetMapping("/cashRecords")
@RestApi
public R<List<CashRecord>> getCashRecord() {
return new R<>(userService.getCashRecord(RequestContext.getCitrusUid()));
}
@PostMapping("/applyCash")
@RestApi
public R<Void> applyCash(@RequestParam Integer money) {
userService.applyMoney(RequestContext.getCitrusUid(), money);
return new R<>(null);
}
}

Loading…
Cancel
Save