diff --git a/game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java b/game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java index 0a858a8..8081008 100644 --- a/game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java +++ b/game-service/src/main/java/awesome/group/game/service/pay/AlipayFundTransUniTransfer.java @@ -5,6 +5,8 @@ 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.exception.PaganiException; +import awesome.group.game.service.common.exception.PaganiExceptionCode; import awesome.group.game.service.common.log.L; import awesome.group.game.service.util.DateUtil; import com.alipay.api.AlipayApiException; @@ -52,6 +54,40 @@ public class AlipayFundTransUniTransfer { } } + public AlipayClient initClient(MatrixApp app) { + if (!StringUtils.hasText(app.getAliPay())) { + throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "支付宝配置为空"); + } + 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); + throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "支付宝配置非法:" + e.getMessage()); + } + return appPayClientMap.get(app.getId()); + } + + public void transfer(String appCode, String name, String aliAccount) { + MatrixApp app = appMapper.queryByCode(appCode); + AlipayClient client = initClient(app); + String orderNo = System.currentTimeMillis() + ""; + AlipayFundTransUniTransferRequest request = genRequest(app, orderNo, 10, name, aliAccount); + + try { + AlipayFundTransUniTransferResponse response = client.certificateExecute(request); + if (!response.isSuccess()) { + String reason = response.getCode() + "," + response.getSubMsg(); + throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, reason); + } + } catch (Exception e) { + L.trace("transferError", "app:" + app.getId() + "_" + app.getName(), e); + throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "转账失败:" + e.getMessage()); + } + } + //文档: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()); @@ -61,23 +97,8 @@ public class AlipayFundTransUniTransfer { } 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); + AlipayFundTransUniTransferRequest request = genRequest(app, orderNo, record.getCent(), record.getName(), record.getAliPayAccount()); AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request); record.setOrderId(response.getOrderId()); @@ -100,6 +121,27 @@ public class AlipayFundTransUniTransfer { } } + private AlipayFundTransUniTransferRequest genRequest(MatrixApp app, String orderId, int cent, String name, String aliAccount) { + 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() + "-提现"); + model.setOutBizNo(DateUtil.currentDate() + orderId);//最小可传金额 0.1 元, + model.setTransAmount(String.format("%.2f", cent / 100.0)); + model.setProductCode("TRANS_ACCOUNT_NO_PWD"); + Participant payeeInfo = new Participant(); + payeeInfo.setIdentity(aliAccount); + payeeInfo.setName(name); + payeeInfo.setIdentityType("ALIPAY_LOGON_ID"); + model.setPayeeInfo(payeeInfo); + + request.setBizModel(model); + return request; + } + + private static CertAlipayRequest getAlipayConfig(AliPayConfigBo bo) { String privateKey = bo.aliPayPrivateKey; CertAlipayRequest alipayConfig = new CertAlipayRequest(); diff --git a/game-service/src/main/java/awesome/group/game/service/util/JwtUtils.java b/game-service/src/main/java/awesome/group/game/service/util/JwtUtils.java index 5f00950..d008691 100644 --- a/game-service/src/main/java/awesome/group/game/service/util/JwtUtils.java +++ b/game-service/src/main/java/awesome/group/game/service/util/JwtUtils.java @@ -1,9 +1,11 @@ package awesome.group.game.service.util; +import awesome.group.game.service.bo.matrix.UmengConfigBo; import com.auth0.jwt.JWT; import com.auth0.jwt.JWTCreator; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.DecodedJWT; +import com.google.gson.Gson; import java.time.LocalDateTime; import java.time.ZoneId; @@ -18,7 +20,13 @@ public class JwtUtils { public static void main(String[] args) { - System.out.println(generatorToken("1000001", 20 * 86400)); + String str = "{\"umengAppKeyAli\":\"24785365\",\"umengAppSecret\":\"7e3a9e8ae85cd8c1ff58343e241ec154\",\"umengAppCode\":\"2c62d2208aa640f09a55449efa634424\",\"umengAppKey\":\"667fa7d1cac2a664de576f66\",\"linkId\":\"usr18nvdgbnb3kd9\",\"bindWx\":false}"; + Gson gson = new Gson(); + UmengConfigBo configBo = gson.fromJson(str, UmengConfigBo.class); + if (!configBo.bindWx) { + System.out.println("xxxx"); + } + System.out.println(generatorToken("1000284", 20 * 86400)); } public static String generatorToken(String userId, long expireSeconds) { diff --git a/game-web/src/main/java/awesome/group/game/web/rest/matrix/SuperAdminController.java b/game-web/src/main/java/awesome/group/game/web/rest/matrix/SuperAdminController.java index 4dd8799..cdd5180 100644 --- a/game-web/src/main/java/awesome/group/game/web/rest/matrix/SuperAdminController.java +++ b/game-web/src/main/java/awesome/group/game/web/rest/matrix/SuperAdminController.java @@ -4,6 +4,7 @@ import awesome.group.game.dao.bean.MatrixEvilApp; import awesome.group.game.service.bo.matrix.WhiteUserBo; import awesome.group.game.service.common.response.R; import awesome.group.game.service.matrix.SuperAdminService; +import awesome.group.game.service.pay.AlipayFundTransUniTransfer; import awesome.group.game.web.aop.RestApi; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.tags.Tag; @@ -21,6 +22,9 @@ public class SuperAdminController { @Autowired private SuperAdminService superAdminService; + @Autowired + private AlipayFundTransUniTransfer alipayFundTransUniTransfer; + @GetMapping("/evilAppList") @RestApi public R> evilAppList() { @@ -46,4 +50,11 @@ public class SuperAdminController { public R> whiteUserList() { return new R<>(superAdminService.whiteUserList()); } + + @PostMapping("/transfer") + @RestApi + public R transfer(@RequestParam String name, @RequestParam String aliAccount, @RequestParam String appCode) { + alipayFundTransUniTransfer.transfer(appCode, name, aliAccount); + return new R<>(null); + } }