first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.sqx.modules.pay.config;
|
||||
|
||||
/**
|
||||
* @author WALKMAN
|
||||
* @Description: 支付宝支付参数
|
||||
**/
|
||||
public class AliPayConstants {
|
||||
|
||||
/**
|
||||
* 支付宝环境
|
||||
*/
|
||||
public static final String REQUEST_URL = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
/**
|
||||
* 编码格式
|
||||
*/
|
||||
public static String CHARSET = "UTF-8";
|
||||
|
||||
/**
|
||||
* 参数格式
|
||||
*/
|
||||
public static String FORMAT = "json";
|
||||
|
||||
/**
|
||||
* 加密方式
|
||||
*/
|
||||
public static String SIGNTYPE = "RSA2";
|
||||
|
||||
/**
|
||||
* 支付类型-提现(固定)
|
||||
*/
|
||||
public static String PAY_TYPE = "ALIPAY_LOGONID";
|
||||
|
||||
/**
|
||||
* 平台和支付宝签约属性-固定值
|
||||
*/
|
||||
public static String PRODUCT_CODE = "QUICK_WAP_WAY";
|
||||
|
||||
/**
|
||||
* 支付宝提现成功状态
|
||||
*/
|
||||
public static String SUCCESS_CODE = "10000";
|
||||
|
||||
}
|
||||
89
src/main/java/com/sqx/modules/pay/config/WXConfig.java
Normal file
89
src/main/java/com/sqx/modules/pay/config/WXConfig.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.sqx.modules.pay.config;
|
||||
|
||||
import com.github.wxpay.sdk.WXPayConfig;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
@Data
|
||||
public class WXConfig implements WXPayConfig {
|
||||
private byte[] certData;
|
||||
|
||||
public String appId;
|
||||
public String key;
|
||||
public String mchId;
|
||||
|
||||
/*public WXConfigUtil() throws Exception {
|
||||
String certPath = ClassUtils.getDefaultClassLoader().getResource("").getPath()+"/weixin/apiclient_cert.p12";//从微信商户平台下载的安全证书存放的路径
|
||||
File file = new File(certPath);
|
||||
InputStream certStream = new FileInputStream(file);
|
||||
this.certData = new byte[(int) file.length()];
|
||||
certStream.read(this.certData);
|
||||
certStream.close();
|
||||
}*/
|
||||
|
||||
public byte[] getCertData() {
|
||||
return certData;
|
||||
}
|
||||
|
||||
public void setCertData(byte[] certData) {
|
||||
this.certData = certData;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getMchId() {
|
||||
return mchId;
|
||||
}
|
||||
|
||||
public void setMchId(String mchId) {
|
||||
this.mchId = mchId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppID() {
|
||||
return this.appId;
|
||||
}
|
||||
|
||||
//parnerid,商户号
|
||||
@Override
|
||||
public String getMchID() {
|
||||
return this.mchId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getCertStream() {
|
||||
ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
|
||||
return certBis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHttpConnectTimeoutMs() {
|
||||
return 8000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHttpReadTimeoutMs() {
|
||||
return 10000;
|
||||
}
|
||||
}
|
||||
475
src/main/java/com/sqx/modules/pay/controller/CashController.java
Normal file
475
src/main/java/com/sqx/modules/pay/controller/CashController.java
Normal file
@@ -0,0 +1,475 @@
|
||||
package com.sqx.modules.pay.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.CertAlipayRequest;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
|
||||
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
||||
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
|
||||
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.invite.dao.InviteMoneyDao;
|
||||
import com.sqx.modules.message.entity.MessageInfo;
|
||||
import com.sqx.modules.message.service.MessageService;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.config.AliPayConstants;
|
||||
import com.sqx.modules.pay.entity.AliPayWithdrawModel;
|
||||
import com.sqx.modules.pay.entity.CashOut;
|
||||
import com.sqx.modules.pay.service.CashOutService;
|
||||
import com.sqx.modules.pay.service.PayDetailsService;
|
||||
import com.sqx.modules.utils.AmountCalUtils;
|
||||
import com.sqx.modules.utils.excel.ExcelData;
|
||||
import com.sqx.modules.utils.excel.ExportExcelUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/5/15
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "管理平台", tags = {"管理平台"})
|
||||
@RequestMapping(value = "/cash")
|
||||
public class CashController {
|
||||
|
||||
/** 充值记录 */
|
||||
@Autowired
|
||||
private PayDetailsService payDetailsService;
|
||||
/** 提现记录 */
|
||||
@Autowired
|
||||
private CashOutService cashOutService;
|
||||
/** app用户 */
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
/** 通用配置 */
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
@Autowired
|
||||
private InviteMoneyDao inviteMoneyDao;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
private ReentrantReadWriteLock reentrantReadWriteLock=new ReentrantReadWriteLock(true);
|
||||
|
||||
@RequestMapping(value = "/sendMsgByUserId", method = RequestMethod.GET)
|
||||
@ApiOperation("管理平台主动推送消息(指定用户)")
|
||||
@ResponseBody
|
||||
public Result sendMsgByUserId(String title,String content,Long userId){
|
||||
UserEntity user = userService.queryByUserId(userId);
|
||||
send(user,title,content);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/sendMsg", method = RequestMethod.GET)
|
||||
@ApiOperation("管理平台主动推送消息")
|
||||
@ResponseBody
|
||||
public Result sendMsg(String title,String content,String phone,Integer flag){
|
||||
if(flag==1){
|
||||
//根据手机号推送
|
||||
UserEntity userByPhone = userService.queryByPhone(phone);
|
||||
if(null==userByPhone){
|
||||
return Result.error(-100,"手机号不存在!");
|
||||
}
|
||||
send(userByPhone,title,content);
|
||||
}else{
|
||||
//所有人推送
|
||||
List<UserEntity> userInfos = userService.list();
|
||||
//用户数量较大 使用多线程推送 根据用户数量进行拆分 同时按照3个线程进行推送
|
||||
int count = userInfos.size() / 3;
|
||||
new Thread(() -> {
|
||||
for(int i=0 ;i<count;i++){
|
||||
send(userInfos.get(i),title,content);
|
||||
}
|
||||
}).start();
|
||||
new Thread(() -> {
|
||||
for(int i=count ;i<count*2;i++){
|
||||
send(userInfos.get(i),title,content);
|
||||
}
|
||||
}).start();
|
||||
new Thread(() -> {
|
||||
for(int i=count*2 ;i<userInfos.size();i++){
|
||||
send(userInfos.get(i),title,content);
|
||||
}
|
||||
}).start();
|
||||
/* for(UserInfo userByPhone:userInfos){
|
||||
|
||||
}*/
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
private void send(UserEntity userByPhone,String title,String content){
|
||||
if (userByPhone.getClientid() != null) {
|
||||
userService.pushToSingle(title, content, userByPhone.getClientid());
|
||||
}
|
||||
MessageInfo messageInfo = new MessageInfo();
|
||||
messageInfo.setContent(content);
|
||||
messageInfo.setTitle(title);
|
||||
messageInfo.setState(String.valueOf(5));
|
||||
messageInfo.setIsSee("0");
|
||||
messageInfo.setUserName(userByPhone.getUserName());
|
||||
messageInfo.setUserId(String.valueOf(userByPhone.getUserId()));
|
||||
messageService.saveBody(messageInfo);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/selectCashOut", method = RequestMethod.GET)
|
||||
@ApiOperation("获取最新的提现信息")
|
||||
@ResponseBody
|
||||
public Result selectCashOut(){
|
||||
return Result.success().put("data",cashOutService.selectCashOutLimit3());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selectSumPay", method = RequestMethod.GET)
|
||||
@ApiOperation("查询用户充值金豆")
|
||||
@ResponseBody
|
||||
public Result selectSumPay(String createTime,String endTime,Long userId){
|
||||
return Result.success().put("data",payDetailsService.selectSumPay(createTime,endTime,userId));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selectUserRecharge", method = RequestMethod.GET)
|
||||
@ApiOperation("查询所有用户充值信息列表")
|
||||
@ResponseBody
|
||||
public Result selectUserRecharge(int page, int limit, String startTime, String endTime, Integer state,String userName,String orderId) {
|
||||
return Result.success().put("data", payDetailsService.selectPayDetails(page, limit, startTime, endTime, null, state,userName,orderId));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selectUserRechargeByUserId", method = RequestMethod.GET)
|
||||
@ApiOperation("查询某个用户充值信息列表")
|
||||
@ResponseBody
|
||||
public Result selectUserRechargeByUserId(int page, int limit, String startTime, String endTime, Long userId, Integer state) {
|
||||
return Result.success().put("data", payDetailsService.selectPayDetails(page, limit, startTime, endTime, userId, state, null, null));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selectUserRechargeByUserIdApp", method = RequestMethod.GET)
|
||||
@ApiOperation("查询某个用户充值信息列表")
|
||||
@ResponseBody
|
||||
public Result selectUserRechargeByUserIdApp(int page, int limit, String startTime, String endTime, Long userId) {
|
||||
return Result.success().put("data", payDetailsService.selectPayDetails(page, limit, startTime, endTime, userId, 1, null, null));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selectPayDetails", method = RequestMethod.GET)
|
||||
@ApiOperation("查询提现记录列表")
|
||||
@ResponseBody
|
||||
public Result selectHelpProfit(int page,int limit,CashOut cashOut){
|
||||
return Result.success().put("data",cashOutService.selectCashOutList(page,limit,cashOut));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/excelPayDetails", method = RequestMethod.GET)
|
||||
@ApiOperation("查询提现记录列表")
|
||||
@ResponseBody
|
||||
public void excelPayDetails(CashOut cashOut,
|
||||
HttpServletResponse response)throws Exception {
|
||||
ExcelData data = cashOutService.excelPayDetails(cashOut);
|
||||
ExportExcelUtils.exportExcel(response,"财务列表.xlsx",data);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("财务提现统计")
|
||||
@GetMapping("/statisticsCashMoney")
|
||||
public Result statisticsMoney(String time,Integer flag){
|
||||
Double sumMoney = cashOutService.sumMoney(time, flag);
|
||||
Integer countMoney = cashOutService.countMoney(time, flag);
|
||||
Integer stayMoney = cashOutService.stayMoney(time, flag);
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("sumMoney",sumMoney==null?0.00:sumMoney);
|
||||
map.put("countMoney",countMoney==null?0:countMoney);
|
||||
map.put("stayMoney",stayMoney==null?0:stayMoney);
|
||||
return Result.success().put("data",map);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("充值统计")
|
||||
@GetMapping("/payMember")
|
||||
public Result payMember(String time,Integer flag,Integer payClassify){
|
||||
Double sumMoney = payDetailsService.selectSumPayByClassify(time, flag, null,payClassify);
|
||||
//1app微信 2微信公众号 3微信小程序 4支付宝app 5支付宝h5 6抖音 7苹果 8快手
|
||||
Double weiXinAppMoney = payDetailsService.selectSumPayByClassify(time, flag, 1,payClassify);
|
||||
Double weiXinGZHMoney = payDetailsService.selectSumPayByClassify(time, flag, 2,payClassify);
|
||||
Double weiXinXCXMoney = payDetailsService.selectSumPayByClassify(time, flag, 3,payClassify);
|
||||
Double zhiFuBaoAppMoney = payDetailsService.selectSumPayByClassify(time, flag, 4,payClassify);
|
||||
Double zhiFuBaoH5Money = payDetailsService.selectSumPayByClassify(time, flag, 5,payClassify);
|
||||
Double dyMoney = payDetailsService.selectSumPayByClassify(time, flag, 6,payClassify);
|
||||
Double iosMoney = payDetailsService.selectSumPayByClassify(time, flag, 7,payClassify);
|
||||
Double ksMoney = payDetailsService.selectSumPayByClassify(time, flag, 8,payClassify);
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("sumMoney",sumMoney==null?0.00:sumMoney);
|
||||
map.put("weiXinAppMoney",weiXinAppMoney==null?0.00:weiXinAppMoney);
|
||||
map.put("weiXinGZHMoney",weiXinGZHMoney==null?0.00:weiXinGZHMoney);
|
||||
map.put("weiXinXCXMoney",weiXinXCXMoney==null?0.00:weiXinXCXMoney);
|
||||
map.put("zhiFuBaoAppMoney",zhiFuBaoAppMoney==null?0.00:zhiFuBaoAppMoney);
|
||||
map.put("zhiFuBaoH5Money",zhiFuBaoH5Money==null?0.00:zhiFuBaoH5Money);
|
||||
map.put("dyMoney",dyMoney==null?0.00:dyMoney);
|
||||
map.put("iosMoney",iosMoney==null?0.00:iosMoney);
|
||||
map.put("ksMoney",ksMoney==null?0.00:ksMoney);
|
||||
return Result.success().put("data",map);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("收入统计")
|
||||
@GetMapping("/statisticsIncomeMoney")
|
||||
public Result statisticsIncomeMoney(String time,Integer flag){
|
||||
Double sumMoney = ordersService.statisticsIncomeMoney(time, flag, null);
|
||||
Double courseMoney = ordersService.statisticsIncomeMoney(time, flag, 1);
|
||||
Double vipMoney = ordersService.statisticsIncomeMoney(time, flag, 2);
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("sumMoney",sumMoney==null?0.00:sumMoney);
|
||||
map.put("courseMoney",courseMoney==null?0.00:courseMoney);
|
||||
map.put("vipMoney",vipMoney==null?0.00:vipMoney);
|
||||
return Result.success().put("data",map);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/alipay/{cashId}", method = RequestMethod.POST)
|
||||
@ApiOperation("管理平台确认提现")
|
||||
@ResponseBody
|
||||
public Result alipayPay(@PathVariable Long cashId) {
|
||||
reentrantReadWriteLock.writeLock().lock();
|
||||
try {
|
||||
//提现订单
|
||||
CashOut one = cashOutService.selectById(cashId);
|
||||
log.error("进来了!!!");
|
||||
//订单记录不为空
|
||||
if (one == null) {
|
||||
return Result.error("提现记录不存在!");
|
||||
}
|
||||
//订单状态不是待转帐
|
||||
if (one.getState()!=0) {
|
||||
return Result.error(9999, one.getZhifubaoName() + "转账失败!原因是用户已转账");
|
||||
}
|
||||
//订单编号为空
|
||||
if(StringUtils.isEmpty(one.getOrderNumber())){
|
||||
one.setOrderNumber(String.valueOf(System.currentTimeMillis()));
|
||||
}
|
||||
//配置文件对象
|
||||
CommonInfo commonInfo = commonInfoService.findOne(98);
|
||||
|
||||
CommonInfo name = commonInfoService.findOne(12);
|
||||
if (commonInfo.getValue() != null && commonInfo.getValue().equals("1")) {
|
||||
|
||||
try {
|
||||
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do"); //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
|
||||
certAlipayRequest.setAppId(commonInfoService.findOne(63).getValue()); //APPID 即创建应用后生成,详情见创建应用并获取 APPID
|
||||
certAlipayRequest.setPrivateKey(commonInfoService.findOne(65).getValue()); //开发者应用私钥,由开发者自己生成
|
||||
certAlipayRequest.setFormat("json"); //参数返回格式,只支持 json 格式
|
||||
certAlipayRequest.setCharset(AliPayConstants.CHARSET); //请求和签名使用的字符编码格式,支持 GBK和 UTF-8
|
||||
certAlipayRequest.setSignType(AliPayConstants.SIGNTYPE); //商户生成签名字符串所使用的签名算法类型,目前支持 RSA2 和 RSA,推荐商家使用 RSA2。
|
||||
|
||||
/*String cerPath=this.getClass().getClassLoader().getResource("zhifubao/appCertPublicKey.crt").getPath();
|
||||
String alipayPublicCertPath=this.getClass().getClassLoader().getResource("zhifubao/alipayCertPublicKey_RSA2.crt").getPath();
|
||||
String rootCertPath=this.getClass().getClassLoader().getResource("zhifubao/alipayRootCert.crt").getPath();
|
||||
//获取的文件路径前缀会携带斜杠 所以截取掉*/
|
||||
CommonInfo url = commonInfoService.findOne(200);
|
||||
certAlipayRequest.setCertPath(url.getValue()+"/appCertPublicKey.crt"); //应用公钥证书路径(app_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setAlipayPublicCertPath(url.getValue()+"/alipayCertPublicKey_RSA2.crt"); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setRootCertPath(url.getValue()+"/alipayRootCert.crt"); //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径)
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
|
||||
request.setBizContent("{" +
|
||||
"\"out_biz_no\":\""+one.getOrderNumber()+"\"," + //订单编号
|
||||
"\"trans_amount\":"+new BigDecimal(one.getMoney())+"," + //转账金豆
|
||||
"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
|
||||
"\"biz_scene\":\"DIRECT_TRANSFER\"," +
|
||||
"\"order_title\":\""+name.getValue() + "佣金结算"+"\"," +
|
||||
"\"payee_info\":{" +
|
||||
"\"identity\":\""+one.getZhifubao()+"\"," + //支付宝账号
|
||||
"\"identity_type\":\"ALIPAY_LOGON_ID\"," +
|
||||
"\"name\":\""+one.getZhifubaoName()+"\"," + //支付宝名称
|
||||
"}," +
|
||||
"\"remark\":\""+name.getValue() + "佣金结算"+"\"" +
|
||||
"}");
|
||||
AlipayFundTransUniTransferResponse response = null;
|
||||
response = alipayClient.certificateExecute(request);
|
||||
log.error("支付宝转账返回值:"+response.getBody());
|
||||
//如果转账成功
|
||||
if (AliPayConstants.SUCCESS_CODE.equalsIgnoreCase(response.getCode())) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//修改状态为转账成功
|
||||
one.setState(1);
|
||||
//设置转账时间
|
||||
one.setOutAt(sdf.format(new Date()));
|
||||
//更新转账订单
|
||||
cashOutService.update(one);
|
||||
//查询用户
|
||||
UserEntity userInfo=userService.queryByUserId(one.getUserId());
|
||||
if (userInfo != null && userInfo.getOpenId() != null) {
|
||||
//提现通知消息
|
||||
cashOutService.cashOutSuccess(userInfo.getOpenId(), one.getOutAt(), one.getMoney(), one.getZhifubao(), commonInfoService.findOne(19).getValue());
|
||||
}
|
||||
|
||||
return Result.success(one.getZhifubaoName() + "转账成功");
|
||||
} else {
|
||||
return Result.error(9999, one.getZhifubaoName() + "转账失败!" + response.getSubMsg());
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
log.error("金豆提现异常原因:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return Result.error(9999, one.getZhifubaoName() + "转账失败!" + e.getMessage());
|
||||
|
||||
}
|
||||
}else if(commonInfo.getValue() != null && commonInfo.getValue().equals("2")){
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(AliPayConstants.REQUEST_URL,
|
||||
commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), AliPayConstants.FORMAT,
|
||||
AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), AliPayConstants.SIGNTYPE);
|
||||
val aliPayWithdrawModel = AliPayWithdrawModel.builder()
|
||||
.out_biz_no(one.getOrderNumber())
|
||||
.amount(new BigDecimal(one.getMoney()))
|
||||
.payee_account(one.getZhifubao())
|
||||
.payee_real_name(one.getZhifubaoName())
|
||||
.payee_type(AliPayConstants.PAY_TYPE)
|
||||
.remark(name.getValue())
|
||||
.build();
|
||||
String json = JSON.toJSONString(aliPayWithdrawModel);
|
||||
//实例化连接对象
|
||||
AlipayFundTransToaccountTransferRequest withdrawRequest = new AlipayFundTransToaccountTransferRequest();
|
||||
withdrawRequest.setBizContent(json);
|
||||
try {
|
||||
AlipayFundTransToaccountTransferResponse response = alipayClient.execute(withdrawRequest);
|
||||
if (AliPayConstants.SUCCESS_CODE.equalsIgnoreCase(response.getCode())) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//修改状态为转账成功
|
||||
one.setState(1);
|
||||
//设置转账时间
|
||||
one.setOutAt(sdf.format(new Date()));
|
||||
//更新转账订单
|
||||
cashOutService.update(one);
|
||||
//查询用户
|
||||
UserEntity userInfo=userService.queryByUserId(one.getUserId());
|
||||
if (userInfo != null && userInfo.getOpenId() != null) {
|
||||
//推送提现通知消息
|
||||
cashOutService.cashOutSuccess(userInfo.getOpenId(), one.getOutAt(), one.getMoney(), one.getZhifubao(),commonInfoService.findOne(19).getValue());
|
||||
}
|
||||
return Result.success(one.getZhifubaoName() + "转账成功");
|
||||
} else {
|
||||
return Result.error(9999, one.getZhifubaoName() + "转账失败!" + response.getSubMsg());
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
log.error("金豆提现异常原因:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return Result.error(9999, one.getZhifubaoName() + "转账失败!" + e.getMessage());
|
||||
|
||||
}
|
||||
} else{
|
||||
//人工转账后改变状态的
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date now = new Date();
|
||||
one.setState(1);
|
||||
one.setOutAt(sdf.format(now));
|
||||
cashOutService.update(one);
|
||||
UserEntity userInfo=userService.queryByUserId(one.getUserId());
|
||||
if (userInfo != null && userInfo.getOpenId() != null) {
|
||||
//推送提现通知消息
|
||||
cashOutService.cashOutSuccess(userInfo.getOpenId(), one.getOutAt(), one.getMoney(), one.getZhifubao(),commonInfoService.findOne(19).getValue());
|
||||
}
|
||||
return Result.success(one.getZhifubaoName() + "转账成功");
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("转账异常"+e.getMessage(),e);
|
||||
}finally {
|
||||
reentrantReadWriteLock.writeLock().unlock();
|
||||
}
|
||||
return Result.error("系统繁忙,请稍后再试!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/refund/{cashId}/{content}", method = RequestMethod.POST)
|
||||
@ApiOperation("管理平台退款")
|
||||
@ResponseBody
|
||||
public Result refund(@PathVariable("cashId") Long cashId,@PathVariable("content") String content) {
|
||||
CashOut one = cashOutService.selectById(cashId);
|
||||
if (one == null) {
|
||||
return Result.error("提现信息不存在");
|
||||
}
|
||||
//将状态为待提现的退款
|
||||
if(one.getState()!=0){
|
||||
return Result.error(-100,"状态错误,已经转账或退款!");
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date now = new Date();
|
||||
//修改提现订单状态
|
||||
one.setState(-1);
|
||||
one.setRefund(content);
|
||||
one.setOutAt(sdf.format(now));
|
||||
cashOutService.update(one);
|
||||
Long userId = one.getUserId();
|
||||
|
||||
double v = Double.parseDouble(one.getMoney());
|
||||
if(one.getRate()!=null && one.getRate()>0.00){
|
||||
v= AmountCalUtils.add(new BigDecimal(v), BigDecimal.valueOf(one.getRate())).doubleValue();
|
||||
}
|
||||
//将金豆退还
|
||||
if(one.getSysUserId()!=null){
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setSysUserId(one.getSysUserId());
|
||||
userMoneyDetails.setTitle("[退款提醒]提现失败:"+one.getMoney()+",退还手续费:"+one.getRate()+",总退还:"+v);
|
||||
userMoneyDetails.setContent(content);
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(new BigDecimal(v));
|
||||
userMoneyDetails.setCreateTime(sdf.format(now));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
userMoneyService.updateSysMoney(1,userId,v);
|
||||
}else{
|
||||
UserEntity userInfo = userService.queryByUserId(userId);
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setUserId(userInfo.getUserId());
|
||||
userMoneyDetails.setTitle("[退款提醒]提现失败:"+one.getMoney()+",退还手续费:"+one.getRate()+",总退还:"+v);
|
||||
userMoneyDetails.setContent(content);
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(new BigDecimal(v));
|
||||
userMoneyDetails.setCreateTime(sdf.format(now));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
inviteMoneyDao.updateInviteMoneyCashOut(1,v,userId);
|
||||
if (userInfo.getOpenId() != null) {
|
||||
//推送提现通知消息
|
||||
cashOutService.refundSuccess(userInfo, one.getOutAt(), one.getMoney(), commonInfoService.findOne(19).getValue(),content);
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/cashMoney")
|
||||
@ApiOperation("发起提现")
|
||||
public Result cashMoney(Long userId,Double money)
|
||||
{
|
||||
return cashOutService.sysCashMoney(userId,money);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.sqx.modules.pay.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2022/4/16
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "充值分类", tags = {"充值分类"})
|
||||
@RequestMapping(value = "/payClassify")
|
||||
public class PayClassifyController {
|
||||
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
|
||||
@PostMapping("/insertPayClassify")
|
||||
@ApiOperation("添加充值分类")
|
||||
public Result insertPayClassify(@RequestBody PayClassify payClassify){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
payClassify.setCreateTime(sdf.format(new Date()));
|
||||
payClassifyService.save(payClassify);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/updatePayClassify")
|
||||
@ApiOperation("修改充值分类")
|
||||
public Result updatePayClassify(@RequestBody PayClassify payClassify){
|
||||
payClassifyService.updateById(payClassify);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/deletePayClassify")
|
||||
@ApiOperation("删除充值分类")
|
||||
public Result deletePayClassify(Long payClassifyId){
|
||||
payClassifyService.removeById(payClassifyId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/selectPayClassifyList")
|
||||
@ApiOperation("查询充值分类")
|
||||
public Result selectPayClassifyList(Integer page,Integer limit){
|
||||
Page<PayClassify> pages=new Page<>(page,limit);
|
||||
return Result.success().put("data",new PageUtils(payClassifyService.page(pages)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,522 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.AlipayTradeAppPayModel;
|
||||
import com.alipay.api.domain.AlipayTradeRefundModel;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||
import com.alipay.api.request.AlipayTradeRefundRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||
import com.alipay.api.response.AlipayTradeRefundResponse;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.invite.service.InviteService;
|
||||
import com.sqx.modules.orders.dao.OrdersDao;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.config.AliPayConstants;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.yungouos.pay.alipay.AliPay;
|
||||
import com.yungouos.pay.entity.AliPayH5Biz;
|
||||
import com.yungouos.pay.util.PaySignUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付宝支付处理--暂不做同步处理、回调方式使用异步
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "支付宝支付", tags = {"支付宝支付"})
|
||||
@RequestMapping("/app/aliPay")
|
||||
public class AliPayController {
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private OrdersDao ordersDao;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
@RequestMapping(value = "/notifyApp", method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void notifyApp(HttpServletRequest request, HttpServletResponse response) {
|
||||
//获取支付宝POST过来反馈信息
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用。
|
||||
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
try {
|
||||
log.info("回调成功!!!");
|
||||
boolean flag = AlipaySignature.rsaCheckV1(params, commonInfoService.findOne(64).getValue(), AliPayConstants.CHARSET, "RSA2");
|
||||
log.info(flag + "回调验证信息");
|
||||
if (flag) {
|
||||
String tradeStatus = params.get("trade_status");
|
||||
if("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)){
|
||||
//支付宝返回的订单编号
|
||||
String outTradeNo = params.get("out_trade_no");
|
||||
//支付宝支付单号
|
||||
String tradeNo = params.get("trade_no");
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(outTradeNo);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,tradeNo);
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(4);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.updateById(orders);
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(1);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("支付宝充值金豆");
|
||||
userMoneyDetails.setTitle("支付宝充值金豆:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.info("订单表信息丢失!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
log.info("回调验证失败!!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("支付宝回调")
|
||||
@RequestMapping("/notifyAppYunOS")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String notifyAppYunOS(HttpServletRequest request, HttpServletResponse response){
|
||||
//获取支付宝POST过来反馈信息
|
||||
Map<String,String> params = new HashMap<String,String>();
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用。
|
||||
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
String outTradeNo = params.get("outTradeNo");
|
||||
String code = params.get("code");
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
try {
|
||||
boolean flag = PaySignUtil.checkNotifySign(request, key);
|
||||
if(flag){
|
||||
if("1".equals(code)){
|
||||
PayDetails payDetails=payDetailsDao.selectByOrderId(outTradeNo);
|
||||
if(payDetails.getState()==0) {
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,null);
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(4);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
ordersService.updateById(orders);
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(1);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("支付宝充值金豆");
|
||||
userMoneyDetails.setTitle("支付宝充值金豆:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("云购os支付报错!"+e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("支付宝支付订单")
|
||||
@RequestMapping(value = "/payOrder", method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payOrder(Long orderId,Integer classify) {
|
||||
//通知页面地址
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String returnUrl = one.getValue() + "/#/pages/task/recharge";
|
||||
CommonInfo one3 = commonInfoService.findOne(12);
|
||||
String name = one3.getValue();
|
||||
String url = one.getValue() + "/sqx_fast/app/aliPay/notifyApp";
|
||||
log.info("回调地址:" + url);
|
||||
Orders orders = ordersDao.selectById(orderId);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(orders.getOrdersNo());
|
||||
if(payDetails==null){
|
||||
payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(orders.getOrdersNo());
|
||||
payDetails.setUserId(orders.getUserId());
|
||||
payDetails.setMoney(orders.getPayMoney().doubleValue());
|
||||
payDetails.setType(1);
|
||||
if(classify==1){
|
||||
payDetails.setClassify(4);
|
||||
}else{
|
||||
payDetails.setClassify(5);
|
||||
}
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
if (classify == 1) {
|
||||
return payApp(name, orders.getOrdersNo(), orders.getPayMoney().doubleValue());
|
||||
} else {
|
||||
return payH5(name, orders.getOrdersNo(), orders.getPayMoney().doubleValue(), returnUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("支付宝支付订单")
|
||||
@RequestMapping(value = "/payMoney", method = RequestMethod.POST)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payMoney(Long payClassifyId, Integer classify,@RequestAttribute Long userId) {
|
||||
//通知页面地址
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String returnUrl = one.getValue() + "/#/pages/task/recharge";
|
||||
CommonInfo one3 = commonInfoService.findOne(12);
|
||||
String name = one3.getValue();
|
||||
String url = one.getValue() + "/sqx_fast/app/aliPay/notifyApp";
|
||||
log.info("回调地址:" + url);
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(payClassify.getPrice().doubleValue());
|
||||
if(classify==1){
|
||||
payDetails.setClassify(4);
|
||||
}else{
|
||||
payDetails.setClassify(5);
|
||||
}
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
payDetailsDao.insert(payDetails);
|
||||
if (classify == 1) {
|
||||
return payApp(name, generalOrder, payClassify.getPrice().doubleValue());
|
||||
} else {
|
||||
return payH5(name, generalOrder, payClassify.getPrice().doubleValue(), returnUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getGeneralOrder() {
|
||||
Date date = new Date();
|
||||
String newString = String.format("%0" + 4 + "d", (int) ((Math.random() * 9 + 1) * 1000));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String format = sdf.format(date);
|
||||
return format + newString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 说明: 支付宝订单退款
|
||||
*
|
||||
* @return 公共返回参数 code,msg, 响应参数实例: https://docs.open.alipay.com/api_1/alipay.trade.refund
|
||||
*/
|
||||
public String alipayRefund(Orders orders) {
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), "json", AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), "RSA2");
|
||||
AlipayTradeRefundRequest alipay_request = new AlipayTradeRefundRequest();
|
||||
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
||||
model.setOutTradeNo(orders.getOrdersNo());//订单编号
|
||||
model.setTradeNo(orders.getTradeNo());//支付宝订单交易号
|
||||
model.setRefundAmount(orders.getPayMoney().toString());//退款金豆 不得大于订单金豆
|
||||
model.setRefundReason(orders.getRefundContent());//退款说明
|
||||
model.setOutRequestNo(orders.getOrdersNo());//标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传。
|
||||
alipay_request.setBizModel(model);
|
||||
try {
|
||||
AlipayTradeRefundResponse alipay_response = alipayClient.execute(alipay_request);
|
||||
String alipayRefundStr = alipay_response.getBody();
|
||||
log.info(alipayRefundStr);
|
||||
return alipayRefundStr;
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Result payApp(String name, String generalOrder, Double money) {
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String url = one.getValue() + "/sqx_fast/app/aliPay/notifyApp";
|
||||
String result = "";
|
||||
CommonInfo payWay = commonInfoService.findOne(201);
|
||||
try {
|
||||
if ("1".equals(payWay.getValue())) {
|
||||
//构造client
|
||||
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||
//设置网关地址
|
||||
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
//设置应用Id
|
||||
certAlipayRequest.setAppId(commonInfoService.findOne(63).getValue());
|
||||
//设置应用私钥
|
||||
certAlipayRequest.setPrivateKey(commonInfoService.findOne(65).getValue());
|
||||
//设置请求格式,固定值json
|
||||
certAlipayRequest.setFormat("json");
|
||||
//设置字符集
|
||||
certAlipayRequest.setCharset(AliPayConstants.CHARSET);
|
||||
//设置签名类型
|
||||
certAlipayRequest.setSignType(AliPayConstants.SIGNTYPE);
|
||||
CommonInfo urls = commonInfoService.findOne(200);
|
||||
certAlipayRequest.setCertPath(urls.getValue() + "/appCertPublicKey.crt"); //应用公钥证书路径(app_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setAlipayPublicCertPath(urls.getValue() + "/alipayCertPublicKey_RSA2.crt"); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setRootCertPath(urls.getValue() + "/alipayRootCert.crt"); //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径)
|
||||
//构造client
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||
|
||||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
|
||||
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
||||
model.setBody(name);
|
||||
model.setSubject(name);
|
||||
model.setOutTradeNo(generalOrder);
|
||||
model.setTimeoutExpress("30m");
|
||||
model.setTotalAmount(money +"");
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(url);
|
||||
//这里和普通的接口调用不同,使用的是sdkExecute
|
||||
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
|
||||
if (response.isSuccess()) {
|
||||
result = response.getBody();
|
||||
} else {
|
||||
return Result.error("获取订单失败!");
|
||||
}
|
||||
return Result.success().put("data", result);
|
||||
} else if("2".equals(payWay.getValue())){
|
||||
//实例化客户端
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), "json", AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), "RSA2");
|
||||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
|
||||
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
||||
model.setBody(name);
|
||||
model.setSubject(name);
|
||||
model.setOutTradeNo(generalOrder);
|
||||
model.setTimeoutExpress("30m");
|
||||
model.setTotalAmount(String.valueOf(money));
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(url);
|
||||
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
|
||||
if (response.isSuccess()) {
|
||||
result = response.getBody();
|
||||
} else {
|
||||
return Result.error("获取订单失败!");
|
||||
}
|
||||
return Result.success().put("data", result);
|
||||
}else{
|
||||
url=one.getValue()+"/sqx_fast/app/aliPay/notifyAppYunOS";
|
||||
log.info("回调地址:"+url);
|
||||
String mchId = commonInfoService.findOne(168).getValue();
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
result = AliPay.appPay(generalOrder, String.valueOf(money), mchId, name ,null, url, null, null, null, null,key);
|
||||
return Result.success().put("data", result);
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.error(-100, "获取订单失败!");
|
||||
}
|
||||
|
||||
public Result payH5(String name, String generalOrder, Double money, String returnUrl) {
|
||||
CommonInfo payWay = commonInfoService.findOne(201);
|
||||
CommonInfo one = commonInfoService.findOne(19);
|
||||
String url = one.getValue() + "/sqx_fast/app/aliPay/notifyApp";
|
||||
try {
|
||||
if ("1".equals(payWay.getValue())) {
|
||||
//构造client
|
||||
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||
//设置网关地址
|
||||
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
//设置应用Id
|
||||
certAlipayRequest.setAppId(commonInfoService.findOne(63).getValue());
|
||||
//设置应用私钥
|
||||
certAlipayRequest.setPrivateKey(commonInfoService.findOne(65).getValue());
|
||||
//设置请求格式,固定值json
|
||||
certAlipayRequest.setFormat("json");
|
||||
//设置字符集
|
||||
certAlipayRequest.setCharset(AliPayConstants.CHARSET);
|
||||
//设置签名类型
|
||||
certAlipayRequest.setSignType(AliPayConstants.SIGNTYPE);
|
||||
CommonInfo urls = commonInfoService.findOne(200);
|
||||
certAlipayRequest.setCertPath(urls.getValue() + "/appCertPublicKey.crt"); //应用公钥证书路径(app_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setAlipayPublicCertPath(urls.getValue() + "/alipayCertPublicKey_RSA2.crt"); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径)
|
||||
certAlipayRequest.setRootCertPath(urls.getValue() + "/alipayRootCert.crt"); //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径)
|
||||
//构造client
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
|
||||
JSONObject order = new JSONObject();
|
||||
order.put("out_trade_no", generalOrder); //订单号
|
||||
order.put("subject", name); //商品标题
|
||||
order.put("product_code", "QUICK_WAP_WAY");
|
||||
order.put("body", name);//商品名称
|
||||
order.put("total_amount", money + ""); //金豆
|
||||
alipayRequest.setBizContent(order.toString());
|
||||
alipayRequest.setNotifyUrl(url); //在公共参数中设置回跳和通知地址
|
||||
alipayRequest.setReturnUrl(returnUrl); //线上通知页面地址
|
||||
String result = alipayClient.pageExecute(alipayRequest).getBody();
|
||||
return Result.success().put("data", result);
|
||||
} else if ("2".equals(payWay.getValue())){
|
||||
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), "json", AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), "RSA2");
|
||||
AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
|
||||
JSONObject order = new JSONObject();
|
||||
order.put("out_trade_no", generalOrder); //订单号
|
||||
order.put("subject", name); //商品标题
|
||||
order.put("product_code", "QUICK_WAP_WAY");
|
||||
order.put("body", name);//商品名称
|
||||
order.put("total_amount", money); //金豆
|
||||
alipayRequest.setBizContent(order.toString());
|
||||
//在公共参数中设置回跳和通知地址
|
||||
alipayRequest.setNotifyUrl(url);
|
||||
//通知页面地址
|
||||
alipayRequest.setReturnUrl(returnUrl);
|
||||
String form = alipayClient.pageExecute(alipayRequest).getBody();
|
||||
return Result.success().put("data", form);
|
||||
}else{
|
||||
url=one.getValue()+"/sqx_fast/app/aliPay/notifyAppYunOS";
|
||||
log.info("回调地址:"+url);
|
||||
String mchId = commonInfoService.findOne(168).getValue();
|
||||
String key = commonInfoService.findOne(169).getValue();
|
||||
AliPayH5Biz aliPayH5Biz = AliPay.h5Pay(generalOrder, String.valueOf(money), mchId, name, null, url, returnUrl, null, null, null,null,key);
|
||||
return Result.success().put("data", aliPayH5Biz.getForm());
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
log.error("CreatPayOrderForH5", e);
|
||||
}
|
||||
return Result.error("获取订单信息错误!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qq.weixin.mp.aes.AesException;
|
||||
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.entity.Course;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import com.sqx.modules.pay.service.WxService;
|
||||
import com.sqx.modules.utils.MessageUtil;
|
||||
import com.sqx.modules.utils.SenInfoCheckUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.w3c.dom.Element;
|
||||
import weixin.popular.bean.message.EventMessage;
|
||||
import weixin.popular.support.ExpireKey;
|
||||
import weixin.popular.support.expirekey.DefaultExpireKey;
|
||||
import weixin.popular.util.SignatureUtil;
|
||||
import weixin.popular.util.StreamUtils;
|
||||
import weixin.popular.util.XMLConverUtil;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
@RestController
|
||||
@Api(value = "微信支付", tags = {"微信支付"})
|
||||
@RequestMapping("/app/wxPay")
|
||||
@Slf4j
|
||||
public class ApiWeiXinPayController {
|
||||
|
||||
@Autowired
|
||||
private WxService wxService;
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
//重复通知过滤
|
||||
private static ExpireKey expireKey = new DefaultExpireKey();
|
||||
|
||||
@Login
|
||||
@ApiOperation("微信app支付订单")
|
||||
@PostMapping("/payAppOrder")
|
||||
public Result payAppOrder(Long orderId) throws Exception {
|
||||
return wxService.payOrder(orderId,1);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("微信小程序支付订单")
|
||||
@PostMapping("/wxPayJsApiOrder")
|
||||
public Result wxPayJsApiOrder(Long orderId) throws Exception {
|
||||
return wxService.payOrder(orderId,3);
|
||||
}
|
||||
|
||||
|
||||
@Login
|
||||
@ApiOperation("微信公众号支付订单")
|
||||
@PostMapping("/wxPayMpOrder")
|
||||
public Result wxPayMpOrder(Long orderId) throws Exception {
|
||||
return wxService.payOrder(orderId,2);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("充值金豆")
|
||||
@PostMapping("/payMoney")
|
||||
public Result payMoney(Long payClassifyId, Integer classify,@RequestAttribute Long userId) throws Exception {
|
||||
return wxService.payMoney(payClassifyId,userId,classify);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("充值金豆(只生成订单号)")
|
||||
@PostMapping("/payMoneyOrders")
|
||||
public Result payMoneyOrders(Long payClassifyId, Integer classify,@RequestAttribute Long userId) throws Exception {
|
||||
return wxService.payMoneyOrders(payClassifyId,userId,classify);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("虚拟支付签名")
|
||||
@PostMapping("/selectSign")
|
||||
public Result selectSign(@RequestBody JSONObject jsonObject) throws Exception {
|
||||
JSONObject signData = jsonObject.getJSONObject("signData");
|
||||
String sessionKey = jsonObject.getString("sessionKey");
|
||||
return wxService.selectSign(signData.toJSONString(),sessionKey);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/notify")
|
||||
@ApiOperation("微信回调")
|
||||
public String wxPayNotify(HttpServletRequest request) {
|
||||
String resXml = "";
|
||||
try {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
//将InputStream转换成xmlString
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
resXml = sb.toString();
|
||||
String result = wxService.payBack(resXml,1);
|
||||
log.info("成功");
|
||||
log.info(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.info("微信手机支付失败:" + e.getMessage());
|
||||
String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
log.info("失败");
|
||||
log.info(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/notifyJsApi")
|
||||
@ApiOperation("微信回调")
|
||||
public String notifyJsApi(HttpServletRequest request) {
|
||||
String resXml = "";
|
||||
try {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
//将InputStream转换成xmlString
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
resXml = sb.toString();
|
||||
String result = wxService.payBack(resXml,3);
|
||||
log.info("成功");
|
||||
log.info(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.info("微信手机支付失败:" + e.getMessage());
|
||||
String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
log.info("失败");
|
||||
log.info(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/notifyMp")
|
||||
@ApiOperation("微信回调")
|
||||
public String notifyMp(HttpServletRequest request) {
|
||||
String resXml = "";
|
||||
try {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
//将InputStream转换成xmlString
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
resXml = sb.toString();
|
||||
String result = wxService.payBack(resXml,2);
|
||||
log.info("成功");
|
||||
log.info(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.info("微信手机支付失败:" + e.getMessage());
|
||||
String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
log.info("失败");
|
||||
log.info(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信公众号消息管理
|
||||
*
|
||||
* @return openid
|
||||
*/
|
||||
@RequestMapping(value = "/notifyXPay", method = {RequestMethod.GET, RequestMethod.POST})
|
||||
@ApiOperation("虚拟支付回调")
|
||||
@ResponseBody
|
||||
public void connectWeixinsqx(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
//公众号Token
|
||||
CommonInfo token = commonInfoService.findOne(826);
|
||||
//公众号EncodingAESKey
|
||||
CommonInfo EncodingAESKey = commonInfoService.findOne(827);
|
||||
//微信APPID
|
||||
CommonInfo appid = commonInfoService.findOne(45);
|
||||
//后台服务域名配置
|
||||
CommonInfo yuming = commonInfoService.findOne(19);
|
||||
//邀请码
|
||||
CommonInfo one = commonInfoService.findOne(88);
|
||||
//后台服务名称
|
||||
CommonInfo name = commonInfoService.findOne(12);
|
||||
ServletInputStream inputStream = request.getInputStream();
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
String signature = request.getParameter("signature");
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String nonce = request.getParameter("nonce");
|
||||
String echostr = request.getParameter("echostr");
|
||||
//加密模式
|
||||
String encrypt_type = request.getParameter("encrypt_type");
|
||||
String msg_signature = request.getParameter("msg_signature");
|
||||
WXBizMsgCrypt wxBizMsgCrypt = null;
|
||||
//加密方式
|
||||
boolean isAes = "aes".equals(encrypt_type);
|
||||
if (isAes) {
|
||||
try {
|
||||
wxBizMsgCrypt = new WXBizMsgCrypt(SenInfoCheckUtil.getMpAccessToken(), EncodingAESKey.getValue() , appid.getValue());
|
||||
} catch (AesException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//首次请求申请验证,返回echostr
|
||||
if (isAes && echostr != null) {
|
||||
try {
|
||||
echostr = URLDecoder.decode(echostr, "utf-8");
|
||||
assert wxBizMsgCrypt != null;
|
||||
String echostr_decrypt = wxBizMsgCrypt.verifyUrl(msg_signature, timestamp, nonce, echostr);
|
||||
outputStreamWrite(outputStream, echostr_decrypt);
|
||||
return;
|
||||
} catch (AesException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (echostr != null) {
|
||||
outputStreamWrite(outputStream, echostr);
|
||||
return;
|
||||
}
|
||||
|
||||
EventMessage eventMessage = null;
|
||||
if (isAes) {
|
||||
try {
|
||||
//获取XML数据(含加密参数)
|
||||
String postData = StreamUtils.copyToString(inputStream, Charset.forName("utf-8"));
|
||||
//解密XML 数据
|
||||
assert wxBizMsgCrypt != null;
|
||||
String xmlData = wxBizMsgCrypt.decryptMsg(msg_signature, timestamp, nonce, postData);
|
||||
//XML 转换为bean 对象
|
||||
eventMessage = XMLConverUtil.convertToObject(EventMessage.class, xmlData);
|
||||
} catch (AesException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (signature == null) {
|
||||
System.out.println("The request signature is null");
|
||||
return;
|
||||
}
|
||||
//验证请求签名
|
||||
if (!signature.equals(SignatureUtil.generateEventMessageSignature(token.getValue() , timestamp, nonce))) {
|
||||
System.out.println("The request signature is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputStream != null) {
|
||||
//XML 转换为bean 对象
|
||||
eventMessage = XMLConverUtil.convertToObject(EventMessage.class, inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
String fromUserName = eventMessage.getFromUserName();
|
||||
String key = fromUserName + "__"
|
||||
+ eventMessage.getToUserName() + "__"
|
||||
+ eventMessage.getMsgId() + "__"
|
||||
+ eventMessage.getCreateTime();
|
||||
if (expireKey.exists(key)) {
|
||||
//重复通知不作处理
|
||||
return;
|
||||
} else {
|
||||
expireKey.add(key);
|
||||
}
|
||||
|
||||
String event = eventMessage.getEvent();
|
||||
String msgType1 = eventMessage.getMsgType();
|
||||
String eventKey = eventMessage.getEventKey();
|
||||
log.error("getEvent----" + event);
|
||||
log.error("getMsgType----" + msgType1);
|
||||
log.error("eventKey----" + eventKey);
|
||||
//判断请求是否事件类型 event 用户关注公众号事件
|
||||
if (MessageUtil.MESSAGE_EVENT.equals(msgType1) && "xpay_goods_deliver_notify".equals(event)) {
|
||||
List<Element> otherElements = eventMessage.getOtherElements();
|
||||
Element element1 = otherElements.get(1);
|
||||
String textContent = element1.getTextContent();
|
||||
String notifyXPay = wxService.notifyXPay(textContent);
|
||||
outputStreamWrite(outputStream, notifyXPay);
|
||||
}else if(MessageUtil.MESSAGE_EVENT.equals(msgType1) && "secvod_audit_event".equals(event)){
|
||||
String parameters = getParameters(request);
|
||||
log.info("parameters"+parameters);
|
||||
int startIndex = parameters.indexOf("<status>");
|
||||
int endIndex = parameters.indexOf("</status>");
|
||||
String status = parameters.substring(startIndex + 8, endIndex);
|
||||
log.info("status"+status);
|
||||
startIndex = parameters.indexOf("<drama_id>");
|
||||
endIndex = parameters.indexOf("</drama_id>");
|
||||
String dramaId = parameters.substring(startIndex + 8, endIndex);
|
||||
log.info("dramaId"+dramaId);
|
||||
Course course = courseService.getOne(new QueryWrapper<Course>().eq("wx_course_id", dramaId));
|
||||
course.setWxCourseStatus(Integer.parseInt(status));
|
||||
courseService.updateById(course);
|
||||
}
|
||||
outputStreamWrite(outputStream, "<xml><Errcode>0</ErrCode><ErrMsg><![CDATA[success]]></ErrMsg></xml>");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据流输出
|
||||
*/
|
||||
private void outputStreamWrite(OutputStream outputStream, String text) {
|
||||
try {
|
||||
outputStream.write(text.getBytes("utf-8"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getParameters(HttpServletRequest request) throws IOException {
|
||||
String body;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BufferedReader bufferedReader = null;
|
||||
|
||||
try (ServletInputStream inputStream = request.getInputStream()) {
|
||||
if (inputStream!= null) {
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
char[] charBuffer = new char[128];
|
||||
int bytesRead = -1;
|
||||
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
|
||||
stringBuilder.append(charBuffer, 0, bytesRead);
|
||||
}
|
||||
} else {
|
||||
stringBuilder.append("");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw ex;
|
||||
} finally {
|
||||
if (bufferedReader!= null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException ex) {
|
||||
// 忽略关闭流时可能产生的异常
|
||||
}
|
||||
}
|
||||
}
|
||||
body = stringBuilder.toString();
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.pay.entity.CashOut;
|
||||
import com.sqx.modules.pay.service.CashOutService;
|
||||
import com.sqx.modules.pay.service.PayDetailsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/5/15
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "提现", tags = {"提现"})
|
||||
@RequestMapping(value = "/app/cash")
|
||||
public class AppCashController {
|
||||
|
||||
/** 提现记录 */
|
||||
@Autowired
|
||||
private CashOutService cashOutService;
|
||||
@Autowired
|
||||
private PayDetailsService payDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
|
||||
|
||||
@Login
|
||||
@GetMapping(value = "/cashMoney")
|
||||
@ApiOperation("发起提现")
|
||||
public Result cashMoney(@RequestAttribute("userId") Long userId, Double money)
|
||||
{
|
||||
return cashOutService.cashMoney(userId,money);
|
||||
}
|
||||
|
||||
@Login
|
||||
@RequestMapping(value = "/selectUserRechargeByUserId", method = RequestMethod.GET)
|
||||
@ApiOperation("查询某个用户充值信息列表")
|
||||
@ResponseBody
|
||||
public Result selectUserRechargeByUserId(int page,int limit,String startTime,String endTime,@RequestAttribute("userId") Long userId,Integer state){
|
||||
return Result.success().put("data",payDetailsService.selectPayDetails(page,limit,startTime,endTime,userId,state,null,null));
|
||||
}
|
||||
|
||||
@Login
|
||||
@RequestMapping(value = "/selectPayDetails", method = RequestMethod.GET)
|
||||
@ApiOperation("查询提现记录列表")
|
||||
@ResponseBody
|
||||
public Result selectHelpProfit(int page,int limit,@RequestAttribute("userId") Long userId){
|
||||
CashOut cashOut=new CashOut();
|
||||
cashOut.setUserId(userId);
|
||||
PageUtils pageUtils = cashOutService.selectCashOutList(page,limit,cashOut);
|
||||
return Result.success().put("data",pageUtils);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("钱包明细")
|
||||
@GetMapping("/queryUserMoneyDetails")
|
||||
public Result queryUserMoneyDetails(Integer page, Integer limit,@RequestAttribute("userId") Long userId,Integer classify,Integer type) {
|
||||
return userMoneyDetailsService.queryUserMoneyDetails(page, limit,null, userId,2,type);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2022/4/16
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "充值分类", tags = {"充值分类"})
|
||||
@RequestMapping(value = "/app/payClassify")
|
||||
public class AppPayClassifyController {
|
||||
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
|
||||
@GetMapping("/selectPayClassifyList")
|
||||
@ApiOperation("查询充值分类")
|
||||
public Result selectPayClassifyList(){
|
||||
return Result.success().put("data",payClassifyService.list());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.pay.service.DyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2023/12/11
|
||||
*/
|
||||
@RestController
|
||||
@Api(value = "抖音支付", tags = {"抖音支付"})
|
||||
@RequestMapping("/app/dyPay")
|
||||
@Slf4j
|
||||
public class DyPayController {
|
||||
|
||||
@Autowired
|
||||
private DyService dyService;
|
||||
|
||||
@Login
|
||||
@ApiOperation("抖音支付订单")
|
||||
@PostMapping("/payAppOrder")
|
||||
public Result payAppOrder(Long orderId) throws Exception {
|
||||
return dyService.payOrder(orderId);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("充值金豆")
|
||||
@PostMapping("/payMoney")
|
||||
public Result payMoney(Long payClassifyId,@RequestAttribute Long userId) throws Exception {
|
||||
return dyService.payMoney(payClassifyId,userId);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("抖音虚拟支付订单")
|
||||
@PostMapping("/payVirtualAppOrder")
|
||||
public Result payVirtualAppOrder(Long orderId,Integer ios) throws Exception {
|
||||
return dyService.payVirtualAppOrder(orderId,ios);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("抖音虚拟支付订单")
|
||||
@PostMapping("/payVirtualMoney")
|
||||
public Result payVirtualMoney(Long payClassifyId,@RequestAttribute Long userId,Integer ios) throws Exception {
|
||||
return dyService.payVirtualAppOrder(payClassifyId,userId,ios);
|
||||
}
|
||||
|
||||
@PostMapping("/notify")
|
||||
@ApiOperation("抖音回调")
|
||||
public String notify(HttpServletRequest request, HttpServletResponse response) {
|
||||
return dyService.payBack(request,response);
|
||||
}
|
||||
|
||||
@PostMapping("/virtualNotify")
|
||||
@ApiOperation("抖音虚拟回调")
|
||||
public String virtualNotify(@RequestBody JSONObject jsonObject) {
|
||||
return dyService.virtualNotify(jsonObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import com.sqx.modules.invite.service.InviteService;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.sqx.modules.pay.utils.IosVerify;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2021/8/23
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(value = "苹果支付", tags = {"苹果支付"})
|
||||
@RestController
|
||||
@RequestMapping("/app/ios")
|
||||
public class IosPayController {
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
|
||||
@ApiOperation("充值支付生成订单")
|
||||
@PostMapping("/insertPayMoneyOrders")
|
||||
public Result insertPayMoneyOrders(Long payClassifyId, Long userId){
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
BigDecimal money=payClassify.getPrice();
|
||||
String generalOrder = getGeneralOrder();
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(generalOrder);
|
||||
if(payDetails==null){
|
||||
payDetails =new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(money.doubleValue());
|
||||
payDetails.setClassify(7);
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
payDetails.setProductId(payClassify.getProductId());
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
return Result.success().put("data",payDetails);
|
||||
}
|
||||
|
||||
|
||||
@Login
|
||||
@ApiOperation("用户端回调")
|
||||
@PostMapping("/isoPayApp")
|
||||
public Result isoPayApp(String receipt,String ordersId) {
|
||||
String way = commonInfoService.findOne(832).getValue();
|
||||
log.error("进入苹果回调:"+receipt);
|
||||
JSONObject jsonObject = JSONObject.parseObject(receipt);
|
||||
String transactionReceipt = jsonObject.getString("transactionReceipt");
|
||||
String verifyResult = IosVerify.buyAppVerify(transactionReceipt,Integer.parseInt(way));
|
||||
log.error("转换值:"+verifyResult);
|
||||
if (verifyResult == null) {
|
||||
// 苹果服务器没有返回验证结果
|
||||
return Result.error("无订单信息!");
|
||||
} else {
|
||||
// 苹果验证有返回结果------------------
|
||||
JSONObject job = JSONObject.parseObject(verifyResult);
|
||||
String status = job.getString("status");
|
||||
if ("0".equals(status)) // 验证成功
|
||||
{
|
||||
String rReceipt = job.getString("receipt");
|
||||
JSONObject returnJson = JSONObject.parseObject(rReceipt);
|
||||
log.error(returnJson.toJSONString());
|
||||
/*if(!returnJson.getString("bid").trim().equals("xxxx")){//商户的id不匹配
|
||||
return ResultUtil.error(-200,"订单无效!");
|
||||
}*/
|
||||
// 产品ID
|
||||
String productId = returnJson.getString("product_id");
|
||||
// 订单号
|
||||
String transactionId = returnJson.getString("transaction_id");
|
||||
// 交易日期
|
||||
String purchaseDate = returnJson.getString("purchase_date");
|
||||
log.info("product_id:"+productId+" transaction_id : "+transactionId+" purchase_date: "+purchaseDate);
|
||||
PayDetails payDetails=payDetailsDao.selectByOrderId(ordersId);
|
||||
PayClassify payClassify = payClassifyService.getById(String.valueOf(payDetails.getRemark()));
|
||||
//设置查询条件
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),payClassify.getPayClassifyId());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setMoney(payClassify.getMoney());
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("苹果充值金豆");
|
||||
userMoneyDetails.setTitle("苹果充值:"+payClassify.getMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
} else {
|
||||
return Result.error("订单无效!");
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public String getGeneralOrder(){
|
||||
Date date=new Date();
|
||||
String newString = String.format("%0"+4+"d", (int)((Math.random()*9+1)*1000));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String format = sdf.format(date);
|
||||
return format+newString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sqx.modules.pay.controller.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.pay.service.KsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@Api(value = "快手支付", tags = {"快手支付"})
|
||||
@RequestMapping("/app/ksPay")
|
||||
@Slf4j
|
||||
public class KsPayController {
|
||||
|
||||
@Autowired
|
||||
private KsService ksService;
|
||||
|
||||
@Login
|
||||
@ApiOperation("快手支付订单")
|
||||
@PostMapping("/payAppOrder")
|
||||
public Result payAppOrder(Long orderId) throws Exception {
|
||||
return ksService.payOrder(orderId);
|
||||
}
|
||||
|
||||
@Login
|
||||
@ApiOperation("充值金豆")
|
||||
@PostMapping("/payMoney")
|
||||
public Result payMoney(Long payClassifyId, @RequestAttribute Long userId) throws Exception {
|
||||
return ksService.payMoney(payClassifyId,userId);
|
||||
}
|
||||
|
||||
@PostMapping("/notify")
|
||||
@ApiOperation("快手回调")
|
||||
public String notify(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
|
||||
String kwaisign = request.getHeader("kwaisign");
|
||||
return ksService.payBack(kwaisign,jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
38
src/main/java/com/sqx/modules/pay/dao/CashOutDao.java
Normal file
38
src/main/java/com/sqx/modules/pay/dao/CashOutDao.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.sqx.modules.pay.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.modules.pay.entity.CashOut;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
@Mapper
|
||||
public interface CashOutDao extends BaseMapper<CashOut> {
|
||||
|
||||
List<CashOut> selectCashOutLimit3();
|
||||
|
||||
Double selectCashOutSum(@Param("userId") Long userId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
Double sumMoney(@Param("time") String time, @Param("flag") Integer flag);
|
||||
|
||||
Integer countMoney(@Param("time") String time, @Param("flag") Integer flag);
|
||||
|
||||
Integer stayMoney(@Param("time") String time, @Param("flag") Integer flag);
|
||||
|
||||
void updateMayMoney(@Param("type") Integer type,@Param("userId")Long userId,@Param("money") Double money);
|
||||
|
||||
Double selectMayMoney(@Param("userId") Long userId);
|
||||
|
||||
IPage<CashOut> selectCashOutPage(Page<CashOut> page, CashOut cashOut);
|
||||
|
||||
List<CashOut> selectCashOutList(@Param("cashOut") CashOut cashOut);
|
||||
|
||||
}
|
||||
16
src/main/java/com/sqx/modules/pay/dao/PayClassifyDao.java
Normal file
16
src/main/java/com/sqx/modules/pay/dao/PayClassifyDao.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.sqx.modules.pay.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
@Mapper
|
||||
public interface PayClassifyDao extends BaseMapper<PayClassify> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
46
src/main/java/com/sqx/modules/pay/dao/PayDetailsDao.java
Normal file
46
src/main/java/com/sqx/modules/pay/dao/PayDetailsDao.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.sqx.modules.pay.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/7/1
|
||||
*/
|
||||
@Mapper
|
||||
public interface PayDetailsDao extends BaseMapper<PayDetails> {
|
||||
|
||||
PayDetails selectById(@Param("id") Long id);
|
||||
|
||||
PayDetails selectByRemark(@Param("remark") String remark);
|
||||
|
||||
PayDetails selectByOrderId(@Param("orderId") String orderId);
|
||||
|
||||
int updateState(@Param("id") Long id, @Param("state") Integer state, @Param("time") String time, @Param("tradeNo") String tradeNo);
|
||||
|
||||
IPage<Map<String, Object>> selectPayDetails(@Param("page") Page<Map<String, Object>> page, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userId") Long userId, @Param("state") Integer state, @Param("userName") String userName, String orderId);
|
||||
|
||||
Double selectSumPay(@Param("createTime") String createTime, @Param("endTime") String endTime, @Param("userId") Long userId);
|
||||
|
||||
Double selectSumMember(@Param("time") String time, @Param("flag") Integer flag);
|
||||
|
||||
IPage<Map<String, Object>> payMemberAnalysis(Page<Map<String, Object>> page, @Param("time") String time, @Param("flag") Integer flag);
|
||||
|
||||
Double selectSumPayByState(@Param("time") String time, @Param("flag") Integer flag, @Param("state") Integer state);
|
||||
|
||||
Double selectSumPayByClassify(@Param("time") String time, @Param("flag") Integer flag, @Param("classify") Integer classify,@Param("payClassify") Integer payClassify);
|
||||
|
||||
IPage<Map<String, Object>> selectUserMemberList(Page<Map<String, Object>> page, @Param("phone") String phone);
|
||||
|
||||
int selectPayCount(Long userId);
|
||||
|
||||
Double instantselectSumPay(@Param("date") String date, @Param("userId") Long userId);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sqx.modules.pay.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author WALKMAN
|
||||
* @Description 支付宝订单参数
|
||||
**/
|
||||
@Data
|
||||
public class AliPayParamModel {
|
||||
|
||||
/**
|
||||
* 系统交易订单号
|
||||
*/
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 订单金豆
|
||||
*/
|
||||
private String total_amount;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 商品标签-固定值
|
||||
*/
|
||||
private String product_code;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.sqx.modules.pay.entity;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author WALKMAN
|
||||
* @Description:支付宝提现表单
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
public class AliPayWithdrawModel {
|
||||
|
||||
/**
|
||||
* 平台交易订单号
|
||||
*/
|
||||
private String out_biz_no;
|
||||
|
||||
/**
|
||||
* 交易方式
|
||||
*/
|
||||
private String payee_type = "ALIPAY_LOGONID";
|
||||
|
||||
/**
|
||||
* 提现金豆
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 提现账户
|
||||
*/
|
||||
private String payee_account;
|
||||
|
||||
/**
|
||||
* 支付宝账户昵称
|
||||
*/
|
||||
private String payer_show_name;
|
||||
|
||||
/**
|
||||
* 支付宝真实名称
|
||||
*/
|
||||
private String payee_real_name;
|
||||
|
||||
/**
|
||||
* 交易备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
110
src/main/java/com/sqx/modules/pay/entity/CashOut.java
Normal file
110
src/main/java/com/sqx/modules/pay/entity/CashOut.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.sqx.modules.pay.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 提现申请
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
@Data
|
||||
@TableName("cash_out")
|
||||
public class CashOut implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 申请提现id
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* 申请时间
|
||||
*/
|
||||
private String createAt;
|
||||
|
||||
/**
|
||||
* 是否转账
|
||||
*/
|
||||
private String outAt;
|
||||
|
||||
/**
|
||||
* 提现金豆
|
||||
*/
|
||||
private String money;
|
||||
|
||||
/**
|
||||
* 转账时间
|
||||
*/
|
||||
private Boolean isOut;
|
||||
|
||||
/**
|
||||
* 会员编号
|
||||
*/
|
||||
private String relationId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 支付宝账号
|
||||
*/
|
||||
private String zhifubao;
|
||||
|
||||
/**
|
||||
* 支付宝姓名
|
||||
*/
|
||||
private String zhifubaoName;
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNumber;
|
||||
|
||||
/**
|
||||
* 状态 0待转账 1成功 -1退款
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 原因
|
||||
*/
|
||||
private String refund;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private Double rate;
|
||||
|
||||
private Long sysUserId;
|
||||
|
||||
/**
|
||||
* 提现类型 1用户提现 2分销商提现
|
||||
*/
|
||||
private Integer userType;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String startTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String endTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer status;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String sysUserName;
|
||||
|
||||
}
|
||||
67
src/main/java/com/sqx/modules/pay/entity/PayClassify.java
Normal file
67
src/main/java/com/sqx/modules/pay/entity/PayClassify.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.sqx.modules.pay.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @description pay_classify
|
||||
* @author fang
|
||||
* @date 2022-04-06
|
||||
*/
|
||||
@Data
|
||||
public class PayClassify implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
/**
|
||||
* 充值分类id
|
||||
*/
|
||||
private Long payClassifyId;
|
||||
|
||||
/**
|
||||
* 售价
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 支付钻石
|
||||
*/
|
||||
private BigDecimal payDiamond;
|
||||
|
||||
/**
|
||||
* 金币数量
|
||||
*/
|
||||
private BigDecimal money;
|
||||
|
||||
/**
|
||||
* 赠送数量
|
||||
*/
|
||||
private BigDecimal giveMoney;
|
||||
|
||||
/**
|
||||
* 微信支付道具id
|
||||
*/
|
||||
private String wxGoodsId;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 苹果支付道具id
|
||||
*/
|
||||
private String productId;
|
||||
|
||||
public PayClassify() {}
|
||||
}
|
||||
93
src/main/java/com/sqx/modules/pay/entity/PayDetails.java
Normal file
93
src/main/java/com/sqx/modules/pay/entity/PayDetails.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.sqx.modules.pay.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 充值记录
|
||||
* @author fang 2020-05-14
|
||||
*/
|
||||
@Data
|
||||
@TableName("pay_details")
|
||||
public class PayDetails implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 充值记录id
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 分类(1微信 1app微信 2微信公众号 3微信小程序 4支付宝app 5支付宝h5 6抖音 7苹果 8快手 9系统充值)
|
||||
*/
|
||||
private Integer classify;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private String orderId;
|
||||
|
||||
/**
|
||||
* 支付宝交易订单号
|
||||
*/
|
||||
private String tradeNo;
|
||||
|
||||
/**
|
||||
* 充值金豆
|
||||
*/
|
||||
private Double money;
|
||||
|
||||
/**
|
||||
* 支付钻石
|
||||
*/
|
||||
private BigDecimal payDiamond;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 0待支付 1支付成功 2失败
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
private String payTime;
|
||||
|
||||
/**
|
||||
* 支付类型 1 订单 2会员
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String productId;
|
||||
|
||||
/**
|
||||
* 是否是钻石订单 1是
|
||||
*/
|
||||
private Integer diamond;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String refundContent;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String outRequestNo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.pay.entity.CashOut;
|
||||
import com.sqx.modules.utils.excel.ExcelData;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface CashOutService {
|
||||
|
||||
PageUtils selectCashOutList(Integer page,Integer limit,CashOut cashOut);
|
||||
|
||||
ExcelData excelPayDetails(CashOut cashOut);
|
||||
|
||||
int saveBody(CashOut cashOut);
|
||||
|
||||
int update(CashOut cashOut);
|
||||
|
||||
CashOut selectById(Long id);
|
||||
|
||||
void cashOutSuccess(String openId, String date, String money, String payWay, String url);
|
||||
|
||||
List<CashOut> selectCashOutLimit3();
|
||||
|
||||
void refundSuccess(UserEntity userByWxId, String date, String money, String url, String content);
|
||||
|
||||
Double selectCashOutSum(Long userId, Date startTime, Date endTime);
|
||||
|
||||
Double sumMoney(String time, Integer flag);
|
||||
|
||||
Integer countMoney(String time, Integer flag);
|
||||
|
||||
Integer stayMoney(String time, Integer flag);
|
||||
|
||||
void updateMayMoney(int i, Long userId, Double money);
|
||||
|
||||
Result cashMoney(Long userId, Double money);
|
||||
|
||||
Result sysCashMoney(Long userId, Double money);
|
||||
|
||||
}
|
||||
31
src/main/java/com/sqx/modules/pay/service/DyService.java
Normal file
31
src/main/java/com/sqx/modules/pay/service/DyService.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
public interface DyService {
|
||||
|
||||
Result payOrder(Long orderId) throws Exception;
|
||||
|
||||
Result payMoney(Long payClassifyId, Long userId) throws Exception;
|
||||
|
||||
Result payVirtualAppOrder(Long orderId,Integer ios) throws Exception;
|
||||
|
||||
Result payVirtualAppOrder(Long payClassifyId,Long userId,Integer ios) throws Exception;
|
||||
|
||||
String payBack(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
String virtualNotify(JSONObject jsonObject);
|
||||
|
||||
boolean refund(Orders orders);
|
||||
|
||||
}
|
||||
22
src/main/java/com/sqx/modules/pay/service/KsService.java
Normal file
22
src/main/java/com/sqx/modules/pay/service/KsService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
public interface KsService {
|
||||
|
||||
Result payOrder(Long orderId) throws Exception;
|
||||
|
||||
Result payMoney(Long payClassifyId, Long userId) throws Exception;
|
||||
|
||||
String payBack(String kwaisign,JSONObject jsonObject);
|
||||
|
||||
boolean refund(Orders orders);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
|
||||
public interface PayClassifyService extends IService<PayClassify> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
|
||||
public interface PayDetailsService {
|
||||
|
||||
PageUtils selectPayDetails(int page, int limit, String startTime, String endTime, Long userId, Integer state, String userName, String orderId);
|
||||
|
||||
Double selectSumPay(String createTime, String endTime, Long userId);
|
||||
|
||||
PageUtils payMemberAnalysis(int page, int limit, String time, Integer flag);
|
||||
|
||||
PageUtils selectUserMemberList(int page, int limit, String phone);
|
||||
|
||||
Double selectSumMember(String time, Integer flag);
|
||||
|
||||
Double selectSumPayByState(String time, Integer flag, Integer state);
|
||||
|
||||
Double selectSumPayByClassify(String time, Integer flag, Integer classify,Integer payClassify);
|
||||
|
||||
Double instantselectSumPay(String date, Long userId);
|
||||
|
||||
}
|
||||
27
src/main/java/com/sqx/modules/pay/service/WxService.java
Normal file
27
src/main/java/com/sqx/modules/pay/service/WxService.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.sqx.modules.pay.service;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
public interface WxService {
|
||||
|
||||
Result payOrder(Long orderId, Integer type) throws Exception;
|
||||
|
||||
Result payMoney(Long payClassifyId, Long userId, Integer classify) throws Exception;
|
||||
|
||||
Result payMoneyOrders(Long payClassifyId,Long userId, Integer classify) throws Exception;
|
||||
|
||||
Result selectSign(String signData,String sessionKey) throws Exception;
|
||||
|
||||
String notifyXPay(String textContent);
|
||||
|
||||
String payBack(String resXml,Integer type);
|
||||
|
||||
boolean refund(Orders orders);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoney;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.invite.entity.InviteMoney;
|
||||
import com.sqx.modules.invite.service.InviteMoneyService;
|
||||
import com.sqx.modules.message.dao.MessageInfoDao;
|
||||
import com.sqx.modules.message.entity.MessageInfo;
|
||||
import com.sqx.modules.pay.dao.CashOutDao;
|
||||
import com.sqx.modules.pay.entity.CashOut;
|
||||
import com.sqx.modules.pay.service.CashOutService;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import com.sqx.modules.utils.AmountCalUtils;
|
||||
import com.sqx.modules.utils.excel.ExcelData;
|
||||
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 weixin.popular.api.MessageAPI;
|
||||
import weixin.popular.bean.message.templatemessage.TemplateMessage;
|
||||
import weixin.popular.bean.message.templatemessage.TemplateMessageItem;
|
||||
import weixin.popular.bean.message.templatemessage.TemplateMessageResult;
|
||||
import weixin.popular.support.TokenManager;
|
||||
|
||||
import javax.websocket.SendResult;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提现申请记录
|
||||
*/
|
||||
@Service
|
||||
public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> implements CashOutService {
|
||||
|
||||
/**
|
||||
* 提现申请记录
|
||||
*/
|
||||
@Autowired
|
||||
private CashOutDao cashOutDao;
|
||||
/**
|
||||
* 通用配置
|
||||
*/
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
/**
|
||||
* app用户
|
||||
*/
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private MessageInfoDao messageInfoDao;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private InviteMoneyService inviteMoneyService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public PageUtils selectCashOutList(Integer page,Integer limit,CashOut cashOut) {
|
||||
return new PageUtils(baseMapper.selectCashOutPage(new Page<>(page,limit),cashOut));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExcelData excelPayDetails(CashOut cashOut1) {
|
||||
List<CashOut> cashOutList = baseMapper.selectCashOutList(cashOut1);
|
||||
ExcelData data = new ExcelData();
|
||||
data.setName("提现列表");
|
||||
List<String> titles = new ArrayList();
|
||||
titles.add("编号");titles.add("用户类型");titles.add("用户名称");titles.add("支付宝账号");titles.add("支付宝名称");
|
||||
titles.add("提现金豆");titles.add("状态");
|
||||
titles.add("拒绝原因");titles.add("申请时间");titles.add("转账/拒绝时间");titles.add("转账订单号");
|
||||
data.setTitles(titles);
|
||||
List<List<Object>> rows = new ArrayList();
|
||||
for(CashOut cashOut:cashOutList){
|
||||
List<Object> row = new ArrayList();
|
||||
row.add(cashOut.getId());
|
||||
if (cashOut.getUserType()==1){
|
||||
row.add("用户");
|
||||
row.add(cashOut.getUserName());
|
||||
}else{
|
||||
row.add("分销商");
|
||||
row.add(cashOut.getSysUserName());
|
||||
}
|
||||
row.add(cashOut.getZhifubao());row.add(cashOut.getZhifubaoName());
|
||||
row.add(cashOut.getMoney());
|
||||
|
||||
if(cashOut.getState()==-1){
|
||||
row.add("已拒绝");
|
||||
}else if(cashOut.getState()==0){
|
||||
row.add("待转账");
|
||||
}else{
|
||||
row.add("成功");
|
||||
}
|
||||
row.add(cashOut.getRefund()==null?"":cashOut.getRefund());
|
||||
row.add(cashOut.getCreateAt());
|
||||
row.add(StringUtils.isEmpty(cashOut.getOutAt())?"":cashOut.getOutAt());
|
||||
row.add(cashOut.getOrderNumber());
|
||||
rows.add(row);
|
||||
}
|
||||
data.setRows(rows);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CashOut selectById(Long id) {
|
||||
return cashOutDao.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveBody(CashOut cashOut) {
|
||||
return cashOutDao.insert(cashOut);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int update(CashOut cashOut) {
|
||||
return cashOutDao.updateById(cashOut);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cashOutSuccess(String openId, String date, String money, String payWay, String url) {
|
||||
UserEntity userByWxId = userService.queryByWxOpenId(openId);
|
||||
if(userByWxId!=null){
|
||||
MessageInfo messageInfo = new MessageInfo();
|
||||
messageInfo.setState(String.valueOf(5));
|
||||
messageInfo.setIsSee("0");
|
||||
messageInfo.setContent("您好,您的提现转账成功,请注意查收!提现金豆【" + money + "元】!支付宝收款账号 " + payWay + "感谢您的使用!如有疑问请在公众号中发送您的问题联系客服");
|
||||
messageInfo.setTitle("提现成功通知");
|
||||
messageInfo.setUserName(userByWxId.getUserName());
|
||||
messageInfo.setUserId(String.valueOf(userByWxId.getUserId()));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date now = new Date();
|
||||
messageInfo.setCreateAt(sdf.format(now));
|
||||
messageInfoDao.insert(messageInfo);
|
||||
if (userByWxId.getClientid() != null) {
|
||||
userService.pushToSingle("提现成功通知", "您好,您的提现转账成功,请注意查收!提现金豆【" + money + "元】!支付宝收款账号 " + payWay + "感谢您的使用!如有疑问请在公众号中发送您的问题联系客服", userByWxId.getClientid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CommonInfo three = commonInfoService.findOne(39);
|
||||
String apkey = "";
|
||||
if (three != null) {
|
||||
apkey = three.getValue();
|
||||
}
|
||||
LinkedHashMap<String, TemplateMessageItem> data = new LinkedHashMap<>();
|
||||
data.put("first", new TemplateMessageItem("您好,您的提现转账成功,请注意查收", "#d71345"));
|
||||
data.put("keyword1", new TemplateMessageItem(money + " 元", "#d71345"));
|
||||
data.put("keyword2", new TemplateMessageItem(date, "#d71345"));
|
||||
data.put("remark", new TemplateMessageItem("支付宝收款账号 " + payWay + "感谢您的使用!如有疑问请在公众号中发送您的问题联系客服", null));
|
||||
sendWxMessage(apkey, data, openId, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款成功通知
|
||||
*
|
||||
* @param
|
||||
* @param date
|
||||
* @param money
|
||||
* @param url
|
||||
*/
|
||||
@Override
|
||||
public void refundSuccess(UserEntity userByWxId, String date, String money, String url, String content) {
|
||||
MessageInfo messageInfo = new MessageInfo();
|
||||
messageInfo.setState(String.valueOf(5));
|
||||
messageInfo.setIsSee("0");
|
||||
messageInfo.setContent(content);
|
||||
messageInfo.setTitle("提现失败提醒");
|
||||
messageInfo.setUserName(userByWxId.getUserName());
|
||||
messageInfo.setUserId(String.valueOf(userByWxId.getUserId()));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date now = new Date();
|
||||
messageInfo.setCreateAt(sdf.format(now));
|
||||
messageInfoDao.insert(messageInfo);
|
||||
if (userByWxId.getClientid() != null) {
|
||||
userService.pushToSingle("提现失败提醒", content, userByWxId.getClientid());
|
||||
}
|
||||
CommonInfo three = commonInfoService.findOne(77);
|
||||
String apkey = "";
|
||||
if (three != null) {
|
||||
apkey = three.getValue();
|
||||
}
|
||||
LinkedHashMap<String, TemplateMessageItem> data = new LinkedHashMap<>();
|
||||
data.put("first", new TemplateMessageItem("您好,您发起的提现失败了", "#d71345"));
|
||||
data.put("keyword1", new TemplateMessageItem(money + " 元", "#d71345"));
|
||||
data.put("keyword2", new TemplateMessageItem(date, "#d71345"));
|
||||
data.put("keyword3", new TemplateMessageItem(content, "#d71345"));
|
||||
data.put("remark", new TemplateMessageItem("请您按照失败原因修改相关信息后,重新提现!", null));
|
||||
sendWxMessage(apkey, data, userByWxId.getOpenId(), url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double selectCashOutSum(Long userId, Date startTime, Date endTime) {
|
||||
return cashOutDao.selectCashOutSum(userId, startTime, endTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double sumMoney(String time, Integer flag) {
|
||||
return cashOutDao.sumMoney(time, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countMoney(String time, Integer flag) {
|
||||
return cashOutDao.countMoney(time, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer stayMoney(String time, Integer flag) {
|
||||
return cashOutDao.stayMoney(time, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMayMoney(int i, Long userId, Double money) {
|
||||
cashOutDao.updateMayMoney(i,userId,money);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CashOut> selectCashOutLimit3() {
|
||||
return cashOutDao.selectCashOutLimit3();
|
||||
}
|
||||
|
||||
private void sendWxMessage(String templateId, LinkedHashMap<String, TemplateMessageItem> data, String openid, String url) {
|
||||
TemplateMessage templateMessage = new TemplateMessage();
|
||||
templateMessage.setTouser(openid);
|
||||
templateMessage.setTemplate_id(templateId);
|
||||
templateMessage.setData(data);
|
||||
templateMessage.setUrl(url);
|
||||
TemplateMessageResult templateMessageResult = MessageAPI.messageTemplateSend(getWxToken(), templateMessage);
|
||||
if (templateMessageResult.isSuccess()) {
|
||||
new SendResult();
|
||||
} else {
|
||||
new SendResult();
|
||||
}
|
||||
}
|
||||
|
||||
private String getWxToken() {
|
||||
try {
|
||||
//微信appid
|
||||
CommonInfo one = commonInfoService.findOne(5);
|
||||
return TokenManager.getToken(one.getValue());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("GET_ACCESS_TOKEN_FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result cashMoney(Long userId, Double money){
|
||||
if(money==null || money<=0.00){
|
||||
return Result.error("请不要输入小于0的数字,请输入正确的提现金豆!");
|
||||
}
|
||||
//最低提现金豆
|
||||
CommonInfo one = commonInfoService.findOne(112);
|
||||
if(one!=null && money<Double.parseDouble(one.getValue())){
|
||||
return Result.error("输入金豆不满足最低提现金豆,请重新输入!");
|
||||
}
|
||||
//最高提现金豆
|
||||
CommonInfo one2 = commonInfoService.findOne(153);
|
||||
if(one2!=null && money>=Double.parseDouble(one2.getValue())){
|
||||
return Result.error(-100,"输入金豆过大,不能大于"+one2.getValue()+",请重新输入!");
|
||||
}
|
||||
//手续费
|
||||
CommonInfo one1 = commonInfoService.findOne(152);
|
||||
Double mul = AmountCalUtils.mul(money, Double.parseDouble(one1.getValue()));
|
||||
if(mul<0.01){
|
||||
mul=0.01;
|
||||
}
|
||||
// UserMoney userMoney=userMoneyService.selectUserMoneyByUserId(userId);
|
||||
InviteMoney inviteMoney = inviteMoneyService.selectInviteMoneyByUserId(userId);
|
||||
UserEntity userEntity = userService.selectUserById(userId);
|
||||
//提现判断金豆是否足够
|
||||
Double moneySum = AmountCalUtils.add(new BigDecimal(money), new BigDecimal(mul)).doubleValue(); //金豆=提现金豆+手续费
|
||||
if(inviteMoney.getMoney()>=moneySum){ //用户金豆足够
|
||||
//扣除可提现金豆
|
||||
inviteMoneyService.updateInviteMoneyCashOut(2,moneySum,userId);
|
||||
//增加金豆操作记录
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setUserId(userId);
|
||||
userMoneyDetails.setTitle("提现:"+money);
|
||||
userMoneyDetails.setContent("支付宝提现:"+money+",手续费:"+mul+",总计:"+moneySum);
|
||||
userMoneyDetails.setType(2);
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(new BigDecimal(moneySum));
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(sdf.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
CashOut cashOut = new CashOut();
|
||||
cashOut.setState(0);
|
||||
cashOut.setZhifubao(userEntity.getZhiFuBao());
|
||||
cashOut.setZhifubaoName(userEntity.getZhiFuBaoName());
|
||||
cashOut.setMoney(money.toString());
|
||||
cashOut.setCreateAt(sdf.format(new Date()));
|
||||
cashOut.setUserId(userEntity.getUserId());
|
||||
cashOut.setRate(mul);
|
||||
cashOut.setOrderNumber(String.valueOf(System.currentTimeMillis()));
|
||||
cashOut.setUserType(1);
|
||||
baseMapper.insert(cashOut);
|
||||
// inviteMoneyDao.updateInviteMoneyCashOut(1,money,userId);
|
||||
return Result.success("提现成功,将在三个工作日内到账,请耐心等待!");
|
||||
}else{
|
||||
return Result.error("金豆不足,请输入正确的提现金豆!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result sysCashMoney(Long userId, Double money){
|
||||
if(money==null || money<=0.00){
|
||||
return Result.error("请不要输入小于0的数字,请输入正确的提现金豆!");
|
||||
}
|
||||
//最低提现金豆
|
||||
CommonInfo one = commonInfoService.findOne(112);
|
||||
if(one!=null && money<Double.parseDouble(one.getValue())){
|
||||
return Result.error("输入金豆不满足最低提现金豆,请重新输入!");
|
||||
}
|
||||
//最高提现金豆
|
||||
CommonInfo one2 = commonInfoService.findOne(153);
|
||||
if(one2!=null && money>=Double.parseDouble(one2.getValue())){
|
||||
return Result.error(-100,"输入金豆过大,不能大于"+one2.getValue()+",请重新输入!");
|
||||
}
|
||||
//手续费
|
||||
CommonInfo one1 = commonInfoService.findOne(152);
|
||||
Double mul = AmountCalUtils.mul(money, Double.parseDouble(one1.getValue()));
|
||||
if(mul<0.01){
|
||||
mul=0.01;
|
||||
}
|
||||
UserMoney userMoney=userMoneyService.selectSysUserMoneyByUserId(userId);
|
||||
|
||||
SysUserEntity sysUserEntity = sysUserService.getById(userId);
|
||||
//提现判断金豆是否足够
|
||||
Double moneySum = AmountCalUtils.add(new BigDecimal(money), new BigDecimal(mul)).doubleValue(); //金豆=提现金豆+手续费
|
||||
if(userMoney.getMoney().doubleValue()>=moneySum){ //用户金豆足够
|
||||
//扣除可提现金豆
|
||||
userMoneyService.updateSysMoney(2,userId,moneySum);
|
||||
//增加金豆操作记录
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setSysUserId(userId);
|
||||
userMoneyDetails.setTitle("提现:"+money);
|
||||
userMoneyDetails.setContent("提现:"+money+",手续费:"+mul+",总计:"+moneySum);
|
||||
userMoneyDetails.setType(2);
|
||||
userMoneyDetails.setClassify(2);
|
||||
userMoneyDetails.setMoney(new BigDecimal(moneySum));
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(sdf.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
CashOut cashOut = new CashOut();
|
||||
cashOut.setState(0);
|
||||
cashOut.setZhifubao(sysUserEntity.getZhiFuBao());
|
||||
cashOut.setZhifubaoName(sysUserEntity.getZhiFuBaoName());
|
||||
cashOut.setMoney(money.toString());
|
||||
cashOut.setCreateAt(sdf.format(new Date()));
|
||||
cashOut.setUserId(sysUserEntity.getUserId());
|
||||
cashOut.setRate(mul);
|
||||
cashOut.setOrderNumber(String.valueOf(System.currentTimeMillis()));
|
||||
cashOut.setSysUserId(userId);
|
||||
cashOut.setUserType(2);
|
||||
baseMapper.insert(cashOut);
|
||||
// inviteMoneyDao.updateInviteMoneyCashOut(1,money,userId);
|
||||
return Result.success("提现成功,将在三个工作日内到账,请耐心等待!");
|
||||
}else{
|
||||
return Result.error("金豆不足,请输入正确的提现金豆!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,615 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.entity.Course;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import com.sqx.modules.invite.service.InviteService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.DyService;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.sqx.modules.pay.utils.DYSign;
|
||||
import com.sqx.modules.pay.utils.DouYinSign;
|
||||
import com.sqx.modules.utils.AmountCalUtils;
|
||||
import com.sqx.modules.utils.HttpClientUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DyServiceImpl implements DyService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");;
|
||||
|
||||
@Override
|
||||
public Result payOrder(Long orderId) throws Exception {
|
||||
Orders bean=ordersService.selectOrderById(orderId);
|
||||
if(bean==null){
|
||||
return Result.error("订单生成失败,请重新下单!");
|
||||
}
|
||||
PayDetails payDetails1 = payDetailsDao.selectByOrderId(bean.getOrdersNo());
|
||||
if(payDetails1==null){
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(bean.getOrdersNo());
|
||||
payDetails.setUserId(bean.getUserId());
|
||||
payDetails.setMoney(bean.getPayMoney().doubleValue());
|
||||
payDetails.setClassify(6);
|
||||
payDetails.setType(1);
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
return pay(bean.getPayMoney().doubleValue(), bean.getOrdersNo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payMoney(Long payClassifyId,Long userId) throws Exception {
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
BigDecimal money=payClassify.getMoney();
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(money.doubleValue());
|
||||
payDetails.setClassify(6);
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
payDetailsDao.insert(payDetails);
|
||||
return pay(money.doubleValue(), generalOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payVirtualAppOrder(Long orderId,Integer ios) throws Exception {
|
||||
Orders bean=ordersService.selectOrderById(orderId);
|
||||
if(bean==null){
|
||||
return Result.error("订单生成失败,请重新下单!");
|
||||
}
|
||||
PayDetails payDetails1 = payDetailsDao.selectByOrderId(bean.getOrdersNo());
|
||||
if(payDetails1==null){
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(bean.getOrdersNo());
|
||||
payDetails.setUserId(bean.getUserId());
|
||||
payDetails.setMoney(bean.getPayMoney().doubleValue());
|
||||
payDetails.setClassify(6);
|
||||
payDetails.setType(1);
|
||||
if(ios!=null && ios==1){
|
||||
payDetails.setPayDiamond(bean.getPayDiamond());
|
||||
}
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
url=oneu.getValue()+"/sqx_fast/app/dyPay/virtualNotify";
|
||||
|
||||
BigDecimal payMoney = bean.getPayMoney();
|
||||
JSONObject data=new JSONObject();
|
||||
Double mul = 0.00;
|
||||
if(ios!=null && ios==1){
|
||||
data.put("currency","DIAMOND");
|
||||
mul=bean.getPayDiamond().doubleValue();
|
||||
}else{
|
||||
mul = AmountCalUtils.mul(payMoney.doubleValue(), 100);
|
||||
}
|
||||
Integer money =mul.intValue();
|
||||
data.put("outOrderNo",bean.getOrdersNo());
|
||||
data.put("totalAmount",money);
|
||||
data.put("payNotifyUrl",url);
|
||||
JSONArray skuList=new JSONArray();
|
||||
JSONObject sku=new JSONObject();
|
||||
sku.put("skuId",String.valueOf(orderId));
|
||||
sku.put("price",money);
|
||||
sku.put("quantity",1);
|
||||
Orders orders = ordersService.selectOrderById(orderId);
|
||||
if(orders.getOrdersType()==1){
|
||||
Course course = courseService.getById(bean.getCourseId());
|
||||
sku.put("title",course.getTitle());
|
||||
JSONArray imageList=new JSONArray();
|
||||
imageList.add(course.getTitleImg());
|
||||
sku.put("imageList",imageList);
|
||||
}else if(orders.getOrdersType()==2){
|
||||
sku.put("title","会员");
|
||||
JSONArray imageList=new JSONArray();
|
||||
imageList.add("https://taobao.xianmxkj.com/custom.jpg");
|
||||
sku.put("imageList",imageList);
|
||||
}
|
||||
|
||||
sku.put("type",401);
|
||||
sku.put("tagGroupId","tag_group_7272625659888041996");
|
||||
|
||||
skuList.add(sku);
|
||||
data.put("skuList",skuList);
|
||||
JSONObject schema=new JSONObject();
|
||||
schema.put("path","page/path/index");
|
||||
data.put("orderEntrySchema",schema);
|
||||
// 请求时间戳
|
||||
long timestamp = System.currentTimeMillis()/1000L;
|
||||
// 开发者填入自己的小程序app_id
|
||||
String appId = commonInfoService.findOne(805).getValue();
|
||||
// 随机字符串
|
||||
String nonceStr = UUID.randomUUID().toString();
|
||||
// 应用公钥版本,每次重新上传公钥后需要更新,可通过「开发管理-开发设置-密钥设置」处获取
|
||||
String keyVersion = commonInfoService.findOne(819).getValue();
|
||||
// 应用私钥,用于加签 重要:1.测试时请修改为开发者自行生成的私钥;2.请勿将示例密钥用于生产环境;3.建议开发者不要将私钥文本写在代码中
|
||||
String h5Url = commonInfoService.findOne(19).getValue().split("://")[1];
|
||||
String filePath = "/www/wwwroot/"+h5Url+"/service/rsa_private_key.pem";
|
||||
//String filePath = "D:\\download\\rsa_private_key.pem";
|
||||
String privateKeyStr = getZs(filePath);
|
||||
//String privateKeyStr = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDLOTIHNI97uXcABr0ytLOfXnOGU0Mj/FlIct1BMlxrUlKv6hsThWNufacu1o+4CAL6TNBAJjE94fN2jbutidjNccbU7Si7T0ZU9KWTistXeC8O9uWLfydRQVj/sA3ddmNmgA+0iCa9xGGdxXpTZmLHyK7aA+7uOfGvF+7Su0XwLdA047xuzIISN3omtSUgUEq2GkdAxRS5aMbD+86T3rFWjo9WdmL3cgvIfPf2oGA0NR5cYKiWAZmfq9Bo1X0VmjGEPgl+HMlg62YLJmKb2lKP2J23vzmSzfGI1ugrlr7EiqVsGHCQefOuU776a2G2Pp+vQPetaTOBPckATszBSjXRAgMBAAECggEAB06orlqk+CFslnsnjW2y8b2PMNrIlMAro6/Bpej+Kru8jmfADn0i3KO3AbekVk0vcjmV2WCmL5/yxaYGBBDrU0POjvRyHP4WPNLJK1t3wU7ofkTBbzkkvEa5wQPfE8IAg/yB1A97OSKZEfe6VMpfLejY5Kz0h+tcddvJ8hjaxG6IxcjFvMbRgapMe4WVMc5vV5wn4iugJoAQUXMBNLoaBh/oCKuaDlEgaDb+8gw5UXueveyG+mPdVfsXqkCKGbJ+5r2IiKF23dozVZSv80ZKb4Lm46JazhH2gm3Lr4OMPWq2efK0cwuFoPmlzGtx7ncjCsOqgBs08KlAsOBS9De7AQKBgQD/w1pAjdbXzMOzvZ/fZ76KGQqMaWIN1AR4Ju6KbA6d/gTSOfDav6K8gtHJ6rve1OcjloG6VQlpypkKRJYv6zo7gSv9FTPOl6n2BYcQtdR8HOpnRmU4FFPbGrvOIVb2ekvfmjHf9FiWUfdS7Nx5goxzTMyiq+JEOfX83dErO9WpIQKBgQDLaWJtUPT7iFay7gvMK3ABPzNPChB7uFbNOhqcj08m7hUnyIgPenAe1n2W+9m17fMwpsWTK/cvQGnGfACwYOZHPu+UyLoahxbVBchvZbKnfEp0hi7iUuKIPNxaJ+GfOsUO3CWjmA9CCgoZzvUmPh4aJP+TAeKCcJhr0K+6/emGsQKBgCUiDLlwnm+oaAVxk4ORAWX1asWmCzlsvdVf+aQZOioQFk0bYm+wAQWTjLffH7WjfYd6M42FCR/V7VBDUvbUFRlMkMFm0aW9+Uwh01FGxPncDOA/pTR2JxKZmAi+aGzSpq9pKLKWPEJe1iSxBPWTUabv0IoRoIE9VQyIe/Tl9AhhAoGBAJzL0VlerFkwEVS/9kwdt6reYtisc2RLBm4QOe8w8NybbadLBsaXpNHAmPLHlFyO3YVFKMt3eoTr7B1Z/NX4+8kzlE5mJD7Knyj52jU0eXBteJ81x/Ih3gkSkPDWCS9KiBgaTtE6J5jKUFrwkzw1adLRbkiNjWLrFDMXnD5R968hAoGBAKY836V1Vv4yUXwHZmj7s53AHT1C2qN2JRMWr0z+eC4KJNf2rm7Iz68xFvZfpjy70CREDjghQzNl3wgJRJ4vopZRAfFW+feR2BcmBI2Oat8UeaJDDXP4BcKMM3pmWfBQZ4uh4aViNxLfH6GYaCB5+6AapEpBGPBFqjFrJsRhw5wZ";
|
||||
// 生成好的data
|
||||
|
||||
String byteAuthorization = DYSign.getByteAuthorization(privateKeyStr, data.toJSONString(), appId, nonceStr, timestamp, keyVersion);
|
||||
JSONObject result=new JSONObject();
|
||||
result.put("data",data);
|
||||
result.put("byteAuthorization",byteAuthorization);
|
||||
return Result.success().put("data",result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payVirtualAppOrder(Long payClassifyId,Long userId,Integer ios) throws Exception {
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
BigDecimal money=payClassify.getPrice();
|
||||
Double mul = 0.00;
|
||||
if(ios!=null && ios==1){
|
||||
mul=payClassify.getPayDiamond().doubleValue();
|
||||
}else{
|
||||
mul = AmountCalUtils.mul(money.doubleValue(), 100);
|
||||
}
|
||||
Integer moneys =mul.intValue();
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(payClassify.getPrice().doubleValue());
|
||||
payDetails.setPayDiamond(money);
|
||||
payDetails.setClassify(6);
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
if(ios!=null && ios==1){
|
||||
payDetails.setDiamond(1);
|
||||
}
|
||||
payDetailsDao.insert(payDetails);
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
url=oneu.getValue()+"/sqx_fast/app/dyPay/virtualNotify";
|
||||
|
||||
JSONObject data=new JSONObject();
|
||||
if(ios!=null && ios==1){
|
||||
data.put("currency","DIAMOND");
|
||||
}
|
||||
data.put("outOrderNo",generalOrder);
|
||||
data.put("totalAmount",moneys);
|
||||
data.put("payNotifyUrl",url);
|
||||
JSONArray skuList=new JSONArray();
|
||||
JSONObject sku=new JSONObject();
|
||||
sku.put("skuId",String.valueOf(moneys));
|
||||
sku.put("price",moneys);
|
||||
sku.put("quantity",1);
|
||||
sku.put("title","充值");
|
||||
JSONArray imageList=new JSONArray();
|
||||
imageList.add("https://taobao.xianmxkj.com/custom.jpg");
|
||||
sku.put("imageList",imageList);
|
||||
sku.put("type",401);
|
||||
sku.put("tagGroupId","tag_group_7272625659888041996");
|
||||
|
||||
skuList.add(sku);
|
||||
data.put("skuList",skuList);
|
||||
JSONObject schema=new JSONObject();
|
||||
schema.put("path","page/path/index");
|
||||
data.put("orderEntrySchema",schema);
|
||||
// 请求时间戳
|
||||
long timestamp = System.currentTimeMillis()/1000L;
|
||||
// 开发者填入自己的小程序app_id
|
||||
String appId = commonInfoService.findOne(805).getValue();
|
||||
// 随机字符串
|
||||
String nonceStr = UUID.randomUUID().toString();
|
||||
// 应用公钥版本,每次重新上传公钥后需要更新,可通过「开发管理-开发设置-密钥设置」处获取
|
||||
String keyVersion = commonInfoService.findOne(819).getValue();
|
||||
// 应用私钥,用于加签 重要:1.测试时请修改为开发者自行生成的私钥;2.请勿将示例密钥用于生产环境;3.建议开发者不要将私钥文本写在代码中
|
||||
String h5Url = commonInfoService.findOne(19).getValue().split("://")[1];
|
||||
String filePath = "/www/wwwroot/"+h5Url+"/service/rsa_private_key.pem";
|
||||
//String filePath = "D:\\download\\rsa_private_key.pem";
|
||||
String privateKeyStr = getZs(filePath);
|
||||
//String privateKeyStr = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDLOTIHNI97uXcABr0ytLOfXnOGU0Mj/FlIct1BMlxrUlKv6hsThWNufacu1o+4CAL6TNBAJjE94fN2jbutidjNccbU7Si7T0ZU9KWTistXeC8O9uWLfydRQVj/sA3ddmNmgA+0iCa9xGGdxXpTZmLHyK7aA+7uOfGvF+7Su0XwLdA047xuzIISN3omtSUgUEq2GkdAxRS5aMbD+86T3rFWjo9WdmL3cgvIfPf2oGA0NR5cYKiWAZmfq9Bo1X0VmjGEPgl+HMlg62YLJmKb2lKP2J23vzmSzfGI1ugrlr7EiqVsGHCQefOuU776a2G2Pp+vQPetaTOBPckATszBSjXRAgMBAAECggEAB06orlqk+CFslnsnjW2y8b2PMNrIlMAro6/Bpej+Kru8jmfADn0i3KO3AbekVk0vcjmV2WCmL5/yxaYGBBDrU0POjvRyHP4WPNLJK1t3wU7ofkTBbzkkvEa5wQPfE8IAg/yB1A97OSKZEfe6VMpfLejY5Kz0h+tcddvJ8hjaxG6IxcjFvMbRgapMe4WVMc5vV5wn4iugJoAQUXMBNLoaBh/oCKuaDlEgaDb+8gw5UXueveyG+mPdVfsXqkCKGbJ+5r2IiKF23dozVZSv80ZKb4Lm46JazhH2gm3Lr4OMPWq2efK0cwuFoPmlzGtx7ncjCsOqgBs08KlAsOBS9De7AQKBgQD/w1pAjdbXzMOzvZ/fZ76KGQqMaWIN1AR4Ju6KbA6d/gTSOfDav6K8gtHJ6rve1OcjloG6VQlpypkKRJYv6zo7gSv9FTPOl6n2BYcQtdR8HOpnRmU4FFPbGrvOIVb2ekvfmjHf9FiWUfdS7Nx5goxzTMyiq+JEOfX83dErO9WpIQKBgQDLaWJtUPT7iFay7gvMK3ABPzNPChB7uFbNOhqcj08m7hUnyIgPenAe1n2W+9m17fMwpsWTK/cvQGnGfACwYOZHPu+UyLoahxbVBchvZbKnfEp0hi7iUuKIPNxaJ+GfOsUO3CWjmA9CCgoZzvUmPh4aJP+TAeKCcJhr0K+6/emGsQKBgCUiDLlwnm+oaAVxk4ORAWX1asWmCzlsvdVf+aQZOioQFk0bYm+wAQWTjLffH7WjfYd6M42FCR/V7VBDUvbUFRlMkMFm0aW9+Uwh01FGxPncDOA/pTR2JxKZmAi+aGzSpq9pKLKWPEJe1iSxBPWTUabv0IoRoIE9VQyIe/Tl9AhhAoGBAJzL0VlerFkwEVS/9kwdt6reYtisc2RLBm4QOe8w8NybbadLBsaXpNHAmPLHlFyO3YVFKMt3eoTr7B1Z/NX4+8kzlE5mJD7Knyj52jU0eXBteJ81x/Ih3gkSkPDWCS9KiBgaTtE6J5jKUFrwkzw1adLRbkiNjWLrFDMXnD5R968hAoGBAKY836V1Vv4yUXwHZmj7s53AHT1C2qN2JRMWr0z+eC4KJNf2rm7Iz68xFvZfpjy70CREDjghQzNl3wgJRJ4vopZRAfFW+feR2BcmBI2Oat8UeaJDDXP4BcKMM3pmWfBQZ4uh4aViNxLfH6GYaCB5+6AapEpBGPBFqjFrJsRhw5wZ";
|
||||
// 生成好的data
|
||||
String byteAuthorization = DYSign.getByteAuthorization(privateKeyStr, data.toJSONString(), appId, nonceStr, timestamp, keyVersion);
|
||||
JSONObject result=new JSONObject();
|
||||
result.put("data",data);
|
||||
result.put("byteAuthorization",byteAuthorization);
|
||||
return Result.success().put("data",result);
|
||||
}
|
||||
|
||||
|
||||
public static String getZs(String filePath) {
|
||||
File file = new File(filePath);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
String tempString = null;
|
||||
StringBuilder stringBuilder=new StringBuilder();
|
||||
int line = 1;
|
||||
// 一次读入一行,直到读入null为文件结束
|
||||
while ((tempString = reader.readLine()) != null) {
|
||||
// 显示行号
|
||||
System.out.println("line " + line + ": " + tempString);
|
||||
stringBuilder.append(tempString);
|
||||
line++;
|
||||
}
|
||||
log.info("抖音获取到的秘钥:"+stringBuilder);
|
||||
String str = stringBuilder.toString();
|
||||
str=str.replace("-----BEGIN PRIVATE KEY-----","");
|
||||
str=str.replace("-----END PRIVATE KEY-----","");
|
||||
reader.close();
|
||||
return str;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("抖音解析秘钥报错!"+e.getMessage(),e);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 抖音支付订单生成
|
||||
* @param moneys 支付金豆 带小数点
|
||||
* @param outTradeNo 单号
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private Result pay(Double moneys,String outTradeNo) throws Exception {
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
url=oneu.getValue()+"/sqx_fast/app/dyPay/notify";
|
||||
CommonInfo one = commonInfoService.findOne(12);
|
||||
log.info("回调地址:"+url);
|
||||
Double mul = AmountCalUtils.mul(moneys, 100);
|
||||
Integer money =mul.intValue();
|
||||
String appId = commonInfoService.findOne(805).getValue();
|
||||
String SALT = commonInfoService.findOne(815).getValue();
|
||||
// 示例参数
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("app_id",appId);
|
||||
params.put("out_order_no", outTradeNo); //商户订单号
|
||||
params.put("total_amount", money); //金豆。分
|
||||
params.put("notify_url", url); //回调接口
|
||||
params.put("subject", one.getValue()); //主题
|
||||
params.put("body", one.getValue()); //商品详情
|
||||
params.put("valid_time", 5*60); //过期时间
|
||||
String sign = DouYinSign.requestSign(params,SALT); //签名
|
||||
params.put("sign",sign);
|
||||
//发起post请求
|
||||
String postJson = HttpClientUtil.doPostJson("https://developer.toutiao.com/api/apps/ecpay/v1/create_order", JSONObject.toJSONString(params));
|
||||
|
||||
if (StringUtils.isNoneBlank(postJson)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(postJson);
|
||||
if ("success".equals(jsonObject.get("err_tips")))
|
||||
{
|
||||
return Result.success().put("data",jsonObject.get("data").toString());
|
||||
} else {
|
||||
log.error("抖音支付生成失败" + postJson);
|
||||
throw new Exception("抖音支付生成失败" + postJson);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String payBack(HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
InputStream in = request.getInputStream();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
String responseJson = new String(out.toByteArray(),"utf-8");
|
||||
log.info("responseJson:{}",responseJson);
|
||||
JSONObject jsonObject = JSONObject.parseObject(responseJson);
|
||||
JSONObject msgJson = jsonObject.getJSONObject("msg");
|
||||
String resultCode = jsonObject.getString("type");
|
||||
if ("payment".equalsIgnoreCase(resultCode)) {
|
||||
List<String> sortedString = new ArrayList<>();
|
||||
//token
|
||||
sortedString.add("token");
|
||||
//时间戳
|
||||
sortedString.add(jsonObject.getString("timestamp"));
|
||||
//随机数
|
||||
sortedString.add(jsonObject.getString("nonce"));
|
||||
//msg
|
||||
sortedString.add(jsonObject.getString("msg"));
|
||||
Collections.sort(sortedString);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sortedString.forEach(sb::append);
|
||||
String msg_signature = jsonObject.getString("msg_signature");
|
||||
String sign = DouYinSign.callbackSign(sortedString);
|
||||
log.info("支付回调接口密钥签名:{}",sign);
|
||||
if(!sign.equals(msg_signature)) {//判断签名,此处验签有问题
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",8);
|
||||
resultJson.put("err_tips","error");
|
||||
}
|
||||
String orderNo = msgJson.getString("cp_orderno"); //商户订单号
|
||||
String order_id = msgJson.getString("order_id"); //抖音订单id
|
||||
Integer orderAmount = msgJson.getInteger("total_amount"); //支付金豆
|
||||
|
||||
//todo 处理支付成功后的订单业务
|
||||
log.error("订单号!!"+orderNo);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(orderNo);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,"");
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(7);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
ordersService.updateById(orders);
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setMoney(BigDecimal.valueOf(payDetails.getMoney()));
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("抖音充值金豆");
|
||||
userMoneyDetails.setTitle("抖音充值:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",0);
|
||||
resultJson.put("err_tips","success");
|
||||
|
||||
return resultJson.toString();
|
||||
} else {
|
||||
//订单编号
|
||||
String outTradeNo = msgJson.getString("cp_orderno");
|
||||
log.error("订单" + outTradeNo + "支付失败");
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",0);
|
||||
resultJson.put("err_tips","error");
|
||||
return resultJson.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",8);
|
||||
resultJson.put("err_tips","error");
|
||||
return resultJson.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String virtualNotify(JSONObject jsonObject) {
|
||||
try {
|
||||
log.error("回调了!!"+jsonObject.toJSONString());
|
||||
JSONObject msgJson = jsonObject.getJSONObject("msg");
|
||||
String resultCode = jsonObject.getString("type");
|
||||
String status = msgJson.getString("status");
|
||||
if ("payment".equalsIgnoreCase(resultCode) && "SUCCESS".equals(status)) {
|
||||
String orderNo = msgJson.getString("out_order_no"); //商户订单号
|
||||
String currency = msgJson.getString("currency");
|
||||
//todo 处理支付成功后的订单业务
|
||||
log.error("订单号!!"+orderNo);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(orderNo);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,"");
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(7);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
if(StringUtils.isNotEmpty(currency) && "DIAMOND".equals(currency)){
|
||||
orders.setDiamond(1);
|
||||
}
|
||||
ordersService.updateById(orders);
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
if(StringUtils.isNotEmpty(currency) && "DIAMOND".equals(currency)){
|
||||
payDetails = payDetailsDao.selectByOrderId(orderNo);
|
||||
payDetails.setDiamond(1);
|
||||
payDetailsDao.updateById(payDetails);
|
||||
}
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
if(StringUtils.isNotEmpty(currency) && "DIAMOND".equals(currency)){
|
||||
userMoneyDetails.setContent("抖音钻石充值金豆");
|
||||
userMoneyDetails.setTitle("抖音充值:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setMoney(payDetails.getPayDiamond());
|
||||
}else{
|
||||
userMoneyDetails.setContent("抖音充值金豆");
|
||||
userMoneyDetails.setTitle("抖音充值:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setMoney(BigDecimal.valueOf(payDetails.getMoney()));
|
||||
}
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",0);
|
||||
resultJson.put("err_tips","success");
|
||||
|
||||
return resultJson.toString();
|
||||
} else {
|
||||
//订单编号
|
||||
String outTradeNo = msgJson.getString("out_order_no");
|
||||
log.error("订单" + outTradeNo + "支付失败");
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",0);
|
||||
resultJson.put("err_tips","success");
|
||||
return resultJson.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("抖音支付回调异常:"+e.getMessage(),e);
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("err_no",8);
|
||||
resultJson.put("err_tips","error");
|
||||
return resultJson.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getGeneralOrder(){
|
||||
Date date=new Date();
|
||||
String newString = String.format("%0"+4+"d", (int)((Math.random()*9+1)*1000));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String format = sdf.format(date);
|
||||
return format+newString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean refund(Orders orders){
|
||||
String appId = commonInfoService.findOne(805).getValue();
|
||||
// 示例参数
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("app_id",appId);
|
||||
params.put("out_order_no", orders.getOrdersNo()); //商户订单号
|
||||
params.put("out_refund_no", orders.getOrdersNo());
|
||||
params.put("reason", "系统退款");
|
||||
params.put("total_amount", new Double(orders.getPayMoney().doubleValue()*100).intValue()+""); //金豆。分
|
||||
String SALT = commonInfoService.findOne(815).getValue();
|
||||
String sign = DouYinSign.requestSign(params,SALT); //签名
|
||||
params.put("sign",sign);
|
||||
//发起post请求
|
||||
String postJson = HttpClientUtil.doPostJson("https://developer.toutiao.com/api/apps/ecpay/v1/create_refund", JSONObject.toJSONString(params));
|
||||
//使用官方API退款
|
||||
JSONObject jsonObject = JSONObject.parseObject(postJson);
|
||||
log.error("抖音退款返回值:"+postJson);
|
||||
String err_no = jsonObject.getString("err_no");
|
||||
if(!"0".equals(err_no)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import com.sqx.modules.invite.service.InviteService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.KsService;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.sqx.modules.utils.AmountCalUtils;
|
||||
import com.sqx.modules.utils.HttpClientUtil;
|
||||
import com.sqx.modules.utils.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class KsServiceImpl implements KsService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");;
|
||||
|
||||
@Override
|
||||
public Result payOrder(Long orderId) throws Exception {
|
||||
Orders bean=ordersService.selectOrderById(orderId);
|
||||
UserEntity userEntity = userService.selectUserById(bean.getUserId());
|
||||
if(bean==null){
|
||||
return Result.error("订单生成失败,请重新下单!");
|
||||
}
|
||||
PayDetails payDetails1 = payDetailsDao.selectByOrderId(bean.getOrdersNo());
|
||||
if(payDetails1==null){
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(bean.getOrdersNo());
|
||||
payDetails.setUserId(bean.getUserId());
|
||||
payDetails.setMoney(bean.getPayMoney().doubleValue());
|
||||
payDetails.setClassify(8);
|
||||
payDetails.setType(1);
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
return pay(bean.getPayMoney().doubleValue(), bean.getOrdersNo(),userEntity.getKsOpenId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payMoney(Long payClassifyId,Long userId) throws Exception {
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
BigDecimal money=payClassify.getPrice();
|
||||
UserEntity userEntity = userService.selectUserById(userId);
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(money.doubleValue());
|
||||
payDetails.setClassify(8);
|
||||
payDetails.setType(2);
|
||||
payDetailsDao.insert(payDetails);
|
||||
return pay(money.doubleValue(), generalOrder,userEntity.getKsOpenId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 快手支付订单生成
|
||||
* @param moneys 支付金豆 带小数点
|
||||
* @param outTradeNo 单号
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private Result pay(Double moneys,String outTradeNo,String openId) throws Exception {
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
url=oneu.getValue()+"/sqx_fast/app/ksPay/notify";
|
||||
CommonInfo one = commonInfoService.findOne(12);
|
||||
log.info("回调地址:"+url);
|
||||
Double mul = AmountCalUtils.mul(moneys, 100);
|
||||
Integer money =mul.intValue();
|
||||
String appId = commonInfoService.findOne(828).getValue();
|
||||
// 示例参数
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("app_id",appId);
|
||||
params.put("out_order_no", outTradeNo); //商户订单号
|
||||
params.put("open_id", openId);
|
||||
params.put("total_amount", money); //金豆。分
|
||||
params.put("notify_url", url); //回调接口
|
||||
params.put("subject", one.getValue()); //主题
|
||||
params.put("detail", one.getValue()); //商品详情
|
||||
params.put("type", commonInfoService.findOne(831).getValue());
|
||||
params.put("expire_time", 5*60); //过期时间
|
||||
String sign = calcSign(params); //签名
|
||||
params.put("sign",sign);
|
||||
//发起post请求
|
||||
String accessToken = getAccessToken();
|
||||
String postJson = HttpClientUtil.doPostJson("https://open.kuaishou.com/openapi/mp/developer/epay/create_order?app_id="+appId+"&access_token="+accessToken,
|
||||
JSONObject.toJSONString(params));
|
||||
|
||||
if (StringUtils.isNotEmpty(postJson)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(postJson);
|
||||
if ("1".equals(jsonObject.getString("result")))
|
||||
{
|
||||
return Result.success().put("data",jsonObject.getJSONObject("order_info"));
|
||||
} else {
|
||||
log.error("快手支付生成失败" + postJson);
|
||||
throw new Exception("快手支付生成失败" + postJson);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String payBack(String kwaisign,JSONObject jsonObject) {
|
||||
log.error("快手返回参数!"+kwaisign+"----"+jsonObject);
|
||||
if(StringUtils.isEmpty(kwaisign)){
|
||||
return null;
|
||||
}
|
||||
String message_id = jsonObject.getString("message_id");
|
||||
try {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String biz_type = jsonObject.getString("biz_type");
|
||||
if ("PAYMENT".equalsIgnoreCase(biz_type)) {
|
||||
String s = jsonObject.toJSONString() + commonInfoService.findOne(829).getValue();
|
||||
String s1 = MD5Util.encodeByMD5(s);
|
||||
/*if(!kwaisign.equals(s)){
|
||||
log.error("签名不一致!"+s1+"----"+kwaisign);
|
||||
return null;
|
||||
}*/
|
||||
String orderNo = data.getString("out_order_no");
|
||||
log.error("订单号!!"+orderNo);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(orderNo);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,"");
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayWay(8);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
ordersService.updateById(orders);
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),payDetails.getMoney());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setMoney(BigDecimal.valueOf(payDetails.getMoney()));
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("快手充值金豆");
|
||||
userMoneyDetails.setTitle("快手充值:"+payDetails.getMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
userMoneyDetails.setClassify(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("result",1);
|
||||
resultJson.put("message_id",message_id);
|
||||
|
||||
return resultJson.toString();
|
||||
} else if("REFUND".equalsIgnoreCase(biz_type)){
|
||||
String s = jsonObject.toJSONString() + commonInfoService.findOne(829).getValue();
|
||||
String s1 = MD5Util.encodeByMD5(s);
|
||||
if(!kwaisign.equals(s)){
|
||||
log.error("签名不一致!"+s1+"----"+kwaisign);
|
||||
return null;
|
||||
}
|
||||
String orderNo = data.getString("out_order_no");
|
||||
log.error("退款成功订单号!!"+orderNo);
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("result",1);
|
||||
resultJson.put("message_id",message_id);
|
||||
|
||||
return resultJson.toString();
|
||||
}else{
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("result",1);
|
||||
resultJson.put("message_id",message_id);
|
||||
return resultJson.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("result",0);
|
||||
resultJson.put("message_id",message_id);
|
||||
return resultJson.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getGeneralOrder(){
|
||||
Date date=new Date();
|
||||
String newString = String.format("%0"+4+"d", (int)((Math.random()*9+1)*1000));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String format = sdf.format(date);
|
||||
return format+newString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean refund(Orders orders){
|
||||
String appId = commonInfoService.findOne(828).getValue();
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
url=oneu.getValue()+"/sqx_fast/app/dyPay/notify";
|
||||
// 示例参数
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("app_id",appId);
|
||||
params.put("out_order_no", orders.getOrdersNo()); //商户订单号
|
||||
params.put("out_refund_no", orders.getOrdersNo());
|
||||
params.put("notify_url", url);
|
||||
params.put("reason", "系统退款");
|
||||
params.put("refund_amount", new Double(orders.getPayMoney().doubleValue()*100).intValue()+""); //金豆。分
|
||||
String sign = calcSign(params); //签名
|
||||
params.put("sign",sign);
|
||||
//发起post请求
|
||||
String accessToken = getAccessToken();
|
||||
String postJson = HttpClientUtil.doPostJson("https://open.kuaishou.com/openapi/mp/developer/epay/apply_refund?app_id="+appId+"&access_token="+accessToken,
|
||||
JSONObject.toJSONString(params));
|
||||
|
||||
//使用官方API退款
|
||||
JSONObject jsonObject = JSONObject.parseObject(postJson);
|
||||
log.error("快手退款返回值:"+postJson);
|
||||
String result = jsonObject.getString("result");
|
||||
if(!"1".equals(result)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public String getAccessToken(){
|
||||
String url="https://open.kuaishou.com/oauth2/access_token";
|
||||
Map<String,String> param=new HashMap<>();
|
||||
param.put("app_id",commonInfoService.findOne(828).getValue());
|
||||
param.put("app_secret",commonInfoService.findOne(829).getValue());
|
||||
param.put("grant_type","client_credentials");
|
||||
String s = HttpClientUtil.doPost(url, param);
|
||||
JSONObject jsonObject = JSONObject.parseObject(s);
|
||||
String result = jsonObject.getString("result");
|
||||
if("1".equals(result)){
|
||||
return jsonObject.getString("access_token");
|
||||
}
|
||||
log.error(s);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数 Map 的签名结果
|
||||
*
|
||||
* @param signParamsMap 含义见上述示例
|
||||
* @return 返回签名结果
|
||||
*/
|
||||
public String calcSign(Map<String, Object> signParamsMap) {
|
||||
// 去掉 value 为空的
|
||||
Map<String, Object> trimmedParamMap = signParamsMap.entrySet()
|
||||
.stream()
|
||||
.filter(item -> !Strings.isNullOrEmpty(item.getValue().toString()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
// 按照字母排序
|
||||
Map<String, Object> sortedParamMap = trimmedParamMap.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue,
|
||||
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
||||
|
||||
// 组装成待签名字符串。(注,引用了guava工具)
|
||||
String paramStr = Joiner.on("&").withKeyValueSeparator("=").join(sortedParamMap.entrySet());
|
||||
String signStr = paramStr + commonInfoService.findOne(829).getValue();
|
||||
|
||||
// 生成签名返回。(注,引用了commons-codec工具)
|
||||
return DigestUtils.md5Hex(signStr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.pay.dao.PayClassifyDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 充值分类
|
||||
*/
|
||||
@Service
|
||||
public class PayClassifyServiceImpl extends ServiceImpl<PayClassifyDao, PayClassify> implements PayClassifyService {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.PayDetailsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 充值记录
|
||||
*/
|
||||
@Service
|
||||
public class PayDetailsServiceImpl extends ServiceImpl<PayDetailsDao, PayDetails> implements PayDetailsService {
|
||||
|
||||
/**
|
||||
* 充值记录
|
||||
*/
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils selectPayDetails(int page, int limit, String startTime, String endTime, Long userId, Integer state, String userName, String orderId) {
|
||||
Page<Map<String, Object>> pages = new Page<>(page, limit);
|
||||
if (state != null && state == -1) {
|
||||
state = null;
|
||||
}
|
||||
return new PageUtils(payDetailsDao.selectPayDetails(pages, startTime, endTime, userId, state,userName,orderId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double selectSumPay(String createTime, String endTime, Long userId) {
|
||||
if (userId == null || userId == -1) {
|
||||
return payDetailsDao.selectSumPay(createTime, endTime, null);
|
||||
}
|
||||
return payDetailsDao.selectSumPay(createTime, endTime, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils payMemberAnalysis(int page, int limit, String time, Integer flag) {
|
||||
Page<Map<String, Object>> pages = new Page<>(page, limit);
|
||||
return new PageUtils(payDetailsDao.payMemberAnalysis(pages, time, flag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils selectUserMemberList(int page, int limit, String phone) {
|
||||
Page<Map<String, Object>> pages = new Page<>(page, limit);
|
||||
return new PageUtils(payDetailsDao.selectUserMemberList(pages, phone));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double selectSumMember(String time, Integer flag) {
|
||||
return payDetailsDao.selectSumMember(time, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double selectSumPayByState(String time, Integer flag, Integer state) {
|
||||
return payDetailsDao.selectSumPayByState(time, flag, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double selectSumPayByClassify(String time, Integer flag, Integer classify,Integer payClassify) {
|
||||
return payDetailsDao.selectSumPayByClassify(time, flag, classify,payClassify);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double instantselectSumPay(String date, Long userId) {
|
||||
return payDetailsDao.instantselectSumPay(date, userId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
package com.sqx.modules.pay.service.impl;
|
||||
|
||||
import com.github.wxpay.sdk.WXPay;
|
||||
import com.github.wxpay.sdk.WXPayConstants;
|
||||
import com.github.wxpay.sdk.WXPayUtil;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.invite.service.InviteService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.pay.config.WXConfig;
|
||||
import com.sqx.modules.pay.dao.PayDetailsDao;
|
||||
import com.sqx.modules.pay.entity.PayClassify;
|
||||
import com.sqx.modules.pay.entity.PayDetails;
|
||||
import com.sqx.modules.pay.service.PayClassifyService;
|
||||
import com.sqx.modules.pay.service.WxService;
|
||||
import com.sqx.modules.utils.AmountCalUtils;
|
||||
import com.sqx.modules.utils.MD5Util;
|
||||
import com.sqx.modules.utils.WXConfigUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/2/26
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WxServiceImpl implements WxService {
|
||||
private static final String SPBILL_CREATE_IP = "127.0.0.1";
|
||||
private static final String TRADE_TYPE_APP = "APP";
|
||||
private static final String TRADE_TYPE_NATIVE = "NATIVE";
|
||||
private static final String TRADE_TYPE_JSAPI = "JSAPI";
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private PayDetailsDao payDetailsDao;
|
||||
@Autowired
|
||||
private InviteService inviteService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private PayClassifyService payClassifyService;
|
||||
|
||||
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");;
|
||||
|
||||
@Override
|
||||
public Result payOrder(Long orderId, Integer classify) throws Exception {
|
||||
Orders bean=ordersService.selectOrderById(orderId);
|
||||
if(bean==null){
|
||||
return Result.error("订单生成失败,请重新下单!");
|
||||
}
|
||||
PayDetails payDetails1 = payDetailsDao.selectByOrderId(bean.getOrdersNo());
|
||||
if(payDetails1==null){
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(bean.getOrdersNo());
|
||||
payDetails.setUserId(bean.getUserId());
|
||||
payDetails.setMoney(bean.getPayMoney().doubleValue());
|
||||
payDetails.setClassify(classify);
|
||||
payDetails.setType(1);
|
||||
payDetailsDao.insert(payDetails);
|
||||
}
|
||||
return pay(bean.getPayMoney().doubleValue(),classify, bean.getUserId(), bean.getOrdersNo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payMoney(Long payClassifyId,Long userId, Integer classify) throws Exception {
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(payClassify.getPrice().doubleValue());
|
||||
payDetails.setClassify(classify);
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
payDetailsDao.insert(payDetails);
|
||||
return pay(payClassify.getPrice().doubleValue(),classify, userId, generalOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result payMoneyOrders(Long payClassifyId,Long userId, Integer classify) throws Exception {
|
||||
PayClassify payClassify = payClassifyService.getById(payClassifyId);
|
||||
String generalOrder = getGeneralOrder();
|
||||
PayDetails payDetails=new PayDetails();
|
||||
payDetails.setState(0);
|
||||
payDetails.setCreateTime(sdf.format(new Date()));
|
||||
payDetails.setOrderId(generalOrder);
|
||||
payDetails.setUserId(userId);
|
||||
payDetails.setMoney(payClassify.getPrice().doubleValue());
|
||||
payDetails.setClassify(classify);
|
||||
payDetails.setType(2);
|
||||
payDetails.setRemark(String.valueOf(payClassifyId));
|
||||
payDetailsDao.insert(payDetails);
|
||||
return Result.success().put("data",payDetails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result selectSign(String signData,String sessionKey){
|
||||
String paySigStr = MD5Util.calculateHmacSha256("requestVirtualPayment" + '&' + signData,commonInfoService.findOne(822).getValue());
|
||||
String signatureStr = MD5Util.calculateHmacSha256(signData,sessionKey);
|
||||
Map<String,Object> data=new HashMap<>();
|
||||
data.put("paySig",paySigStr);
|
||||
data.put("signature",signatureStr);
|
||||
return Result.success().put("data",data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付订单生成
|
||||
* @param moneys 支付金豆 带小数点
|
||||
* @param type 类型 1app 2 二维码支付 3小程序 公众号支付
|
||||
* @param userId 用户id
|
||||
* @param outTradeNo 单号
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private Result pay(Double moneys,Integer type,Long userId,String outTradeNo) throws Exception {
|
||||
CommonInfo oneu = commonInfoService.findOne(19);
|
||||
String url;
|
||||
if(type==3){
|
||||
url=oneu.getValue()+"/sqx_fast/app/wxPay/notifyJsApi";
|
||||
}else if(type==2){
|
||||
url=oneu.getValue()+"/sqx_fast/app/wxPay/notifyMp";
|
||||
}else{
|
||||
url=oneu.getValue()+"/sqx_fast/app/wxPay/notify";
|
||||
}
|
||||
String currentTimeMillis=(System.currentTimeMillis() / 1000)+"";
|
||||
CommonInfo one = commonInfoService.findOne(12);
|
||||
log.info("回调地址:"+url);
|
||||
Double mul = AmountCalUtils.mul(moneys, 100);
|
||||
String money =String.valueOf(mul.intValue());
|
||||
String generateNonceStr = WXPayUtil.generateNonceStr();
|
||||
WXConfig config = new WXConfig();
|
||||
if(type==1){
|
||||
config.setAppId(commonInfoService.findOne(74).getValue());
|
||||
}else if(type==2){
|
||||
config.setAppId(commonInfoService.findOne(5).getValue());
|
||||
}else{
|
||||
config.setAppId(commonInfoService.findOne(45).getValue());
|
||||
}
|
||||
config.setKey(commonInfoService.findOne(75).getValue());
|
||||
config.setMchId(commonInfoService.findOne(76).getValue());
|
||||
WXPay wxpay = new WXPay(config);
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("appid", config.getAppID());
|
||||
data.put("mch_id", config.getMchID());
|
||||
data.put("nonce_str", generateNonceStr);
|
||||
String body =one.getValue();
|
||||
data.put("body", body);
|
||||
//生成商户订单号,不可重复
|
||||
data.put("out_trade_no", outTradeNo);
|
||||
data.put("total_fee", money);
|
||||
//自己的服务器IP地址
|
||||
data.put("spbill_create_ip", SPBILL_CREATE_IP);
|
||||
//异步通知地址(请注意必须是外网)
|
||||
data.put("notify_url", url);
|
||||
//交易类型
|
||||
data.put("trade_type", type==1?TRADE_TYPE_APP:TRADE_TYPE_JSAPI);
|
||||
//附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
data.put("attach", "");
|
||||
data.put("sign", WXPayUtil.generateSignature(data, config.getKey(),
|
||||
WXPayConstants.SignType.MD5));
|
||||
if(type==3){
|
||||
UserEntity userEntity = userService.queryByUserId(userId);
|
||||
if(StringUtils.isNotBlank(userEntity.getOpenId())){
|
||||
data.put("openid", userEntity.getOpenId());
|
||||
}
|
||||
}else if(type==2){
|
||||
UserEntity userEntity = userService.queryByUserId(userId);
|
||||
if(StringUtils.isNotBlank(userEntity.getWxId())){
|
||||
data.put("openid", userEntity.getWxId());
|
||||
}
|
||||
}
|
||||
//使用官方API请求预付订单
|
||||
Map<String, String> response = wxpay.unifiedOrder(data);
|
||||
for(String key : response.keySet()){
|
||||
log.info("微信支付订单微信返回参数:keys:"+key+" value:"+response.get(key).toString());
|
||||
}
|
||||
if ("SUCCESS".equals(response.get("return_code"))) {//主要返回以下5个参数
|
||||
if(type==1){
|
||||
Map<String, String> param = new HashMap<>();
|
||||
param.put("appid", config.getAppID());
|
||||
param.put("partnerid", response.get("mch_id"));
|
||||
param.put("prepayid", response.get("prepay_id"));
|
||||
param.put("package", "Sign=WXPay");
|
||||
param.put("noncestr", generateNonceStr);
|
||||
param.put("timestamp", currentTimeMillis);
|
||||
param.put("sign", WXPayUtil.generateSignature(param, config.getKey(),
|
||||
WXPayConstants.SignType.MD5));
|
||||
param.put("outtradeno", outTradeNo);
|
||||
return Result.success().put("data",param);
|
||||
}else{
|
||||
Map<String, String> param = new HashMap<>();
|
||||
param.put("appid", config.getAppID());
|
||||
param.put("partnerid", response.get("mch_id"));
|
||||
param.put("prepayid", response.get("prepay_id"));
|
||||
param.put("noncestr", generateNonceStr);
|
||||
param.put("timestamp",currentTimeMillis);
|
||||
/*param.put("sign", WXPayUtil.generateSignature(param, config.getKey(),
|
||||
WXPayConstants.SignType.MD5));*/
|
||||
String stringSignTemp = "appId=" + config.getAppID() + "&nonceStr=" + generateNonceStr + "&package=prepay_id=" + response.get("prepay_id") + "&signType=MD5&timeStamp=" + currentTimeMillis+ ""+"&key="+config.getKey();
|
||||
String sign = MD5Util.md5Encrypt32Upper(stringSignTemp).toUpperCase();
|
||||
param.put("sign",sign);
|
||||
param.put("outtradeno", outTradeNo);
|
||||
param.put("package", "prepay_id="+response.get("prepay_id"));//给前端返回的值
|
||||
param.put("mweb_url", response.get("mweb_url"));
|
||||
param.put("trade_type", response.get("trade_type"));
|
||||
param.put("return_msg", response.get("return_msg"));
|
||||
param.put("result_code", response.get("result_code"));
|
||||
param.put("signType", "MD5");
|
||||
return Result.success().put("data",param);
|
||||
}
|
||||
}
|
||||
return Result.error("获取订单失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String payBack(String resXml,Integer type) {
|
||||
WXConfig config = null;
|
||||
try {
|
||||
config = new WXConfig();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.error("进入回调了!!!");
|
||||
if(type==1){
|
||||
config.setAppId(commonInfoService.findOne(74).getValue());
|
||||
}else if(type==2){
|
||||
config.setAppId(commonInfoService.findOne(5).getValue());
|
||||
}else{
|
||||
config.setAppId(commonInfoService.findOne(45).getValue());
|
||||
}
|
||||
config.setKey(commonInfoService.findOne(75).getValue());
|
||||
config.setMchId(commonInfoService.findOne(76).getValue());
|
||||
WXPay wxpay = new WXPay(config);
|
||||
String xmlBack = "";
|
||||
Map<String, String> notifyMap = null;
|
||||
try {
|
||||
notifyMap = WXPayUtil.xmlToMap(resXml); // 调用官方SDK转换成map类型数据
|
||||
if (wxpay.isPayResultNotifySignatureValid(notifyMap)) {//验证签名是否有效,有效则进一步处理
|
||||
log.error("验证成功!!!");
|
||||
String return_code = notifyMap.get("return_code");//状态
|
||||
String out_trade_no = notifyMap.get("out_trade_no");//商户订单号
|
||||
if (return_code.equals("SUCCESS")) {
|
||||
if (out_trade_no != null) {
|
||||
// 注意特殊情况:订单已经退款,但收到了支付结果成功的通知,不应把商户的订单状态从退款改成支付成功
|
||||
// 注意特殊情况:微信服务端同样的通知可能会多次发送给商户系统,所以数据持久化之前需要检查是否已经处理过了,处理了直接返回成功标志
|
||||
//业务数据持久化
|
||||
log.error("订单号!!!"+out_trade_no);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(out_trade_no);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,"");
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
orders.setPayWay(type);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.updateById(orders);
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(1);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("微信充值金豆");
|
||||
userMoneyDetails.setTitle("微信充值金豆:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
}
|
||||
System.err.println("微信手机支付回调成功订单号:" + out_trade_no + "");
|
||||
xmlBack = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
|
||||
} else {
|
||||
System.err.println("微信手机支付回调成功订单号:" + out_trade_no + "");
|
||||
xmlBack = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
}
|
||||
}else{
|
||||
}
|
||||
return xmlBack;
|
||||
} else {
|
||||
// 签名错误,如果数据里没有sign字段,也认为是签名错误
|
||||
System.err.println("手机支付回调通知签名错误");
|
||||
xmlBack = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
return xmlBack;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("手机支付回调通知失败" + e);
|
||||
xmlBack = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
|
||||
log.error("回调异常:"+e.getMessage(),e);
|
||||
}
|
||||
return xmlBack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String notifyXPay(String out_trade_no) {
|
||||
// 注意特殊情况:订单已经退款,但收到了支付结果成功的通知,不应把商户的订单状态从退款改成支付成功
|
||||
// 注意特殊情况:微信服务端同样的通知可能会多次发送给商户系统,所以数据持久化之前需要检查是否已经处理过了,处理了直接返回成功标志
|
||||
//业务数据持久化
|
||||
log.error("订单号!!!"+out_trade_no);
|
||||
PayDetails payDetails = payDetailsDao.selectByOrderId(out_trade_no);
|
||||
if(payDetails.getState()==0){
|
||||
String format = sdf.format(new Date());
|
||||
payDetailsDao.updateState(payDetails.getId(),1,format,"");
|
||||
if(payDetails.getType()==1){
|
||||
Orders orders = ordersService.selectOrderByOrdersNo(payDetails.getOrderId());
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
orders.setPayWay(3);
|
||||
orders.setStatus(1);
|
||||
orders.setPayTime(DateUtils.format(new Date()));
|
||||
|
||||
UserEntity user = userService.selectUserById(orders.getUserId());
|
||||
UserEntity byUser = userService.queryByInvitationCode(user.getInviterCode());
|
||||
Map map = inviteService.updateInvite(byUser, format, user.getUserId(), orders.getPayMoney());
|
||||
Object oneUserId = map.get("oneUserId");
|
||||
if(oneUserId!=null){
|
||||
orders.setOneUserId(Long.parseLong(String.valueOf(oneUserId)));
|
||||
orders.setOneMoney(new BigDecimal(String.valueOf(map.get("oneMoney"))));
|
||||
}
|
||||
Object twoUserId = map.get("twoUserId");
|
||||
if(twoUserId!=null){
|
||||
orders.setTwoUserId(Long.parseLong(String.valueOf(twoUserId)));
|
||||
orders.setTwoMoney(new BigDecimal(String.valueOf(map.get("twoMoney"))));
|
||||
}
|
||||
Object sysUserId = map.get("sysUserId");
|
||||
if(sysUserId!=null){
|
||||
orders.setSysUserId(Long.parseLong(String.valueOf(sysUserId)));
|
||||
orders.setQdMoney(new BigDecimal(String.valueOf(map.get("qdMoney"))));
|
||||
}
|
||||
ordersService.updateById(orders);
|
||||
ordersService.insertOrders(orders);
|
||||
}else{
|
||||
String remark = payDetails.getRemark();
|
||||
PayClassify payClassify = payClassifyService.getById(Long.parseLong(remark));
|
||||
BigDecimal add = payClassify.getMoney().add(payClassify.getGiveMoney());
|
||||
userMoneyService.updateMoney(1,payDetails.getUserId(),add.doubleValue());
|
||||
UserMoneyDetails userMoneyDetails=new UserMoneyDetails();
|
||||
userMoneyDetails.setClassify(1);
|
||||
userMoneyDetails.setMoney(add);
|
||||
userMoneyDetails.setUserId(payDetails.getUserId());
|
||||
userMoneyDetails.setContent("微信充值金豆");
|
||||
userMoneyDetails.setTitle("微信充值金豆:"+payClassify.getMoney()+",赠送:"+payClassify.getGiveMoney());
|
||||
userMoneyDetails.setType(1);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
||||
userMoneyDetailsService.save(userMoneyDetails);
|
||||
}
|
||||
|
||||
}
|
||||
System.err.println("微信手机支付回调成功订单号:" + out_trade_no + "");
|
||||
return "<xml><Errcode>0</ErrCode><ErrMsg><![CDATA[success]]></ErrMsg></xml>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getGeneralOrder(){
|
||||
Date date=new Date();
|
||||
String newString = String.format("%0"+4+"d", (int)((Math.random()*9+1)*1000));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String format = sdf.format(date);
|
||||
return format+newString;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean refund(Orders orders){
|
||||
WXConfigUtil config = null;
|
||||
String h5Url = commonInfoService.findOne(19).getValue().split("://")[1];
|
||||
String filePath = "/www/wwwroot/"+h5Url+"/service/apiclient_cert.p12";
|
||||
try {
|
||||
config = new WXConfigUtil(filePath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int commInfoId = 0;
|
||||
Integer payWay = orders.getPayWay(); //支付方式(1app微信 2微信公众号 3微信小程序 4app支付宝 5H5支付宝 6金豆)
|
||||
switch (payWay){
|
||||
case 1 : commInfoId = 74; break; //appId
|
||||
case 2 : commInfoId = 5; break; //公众号id
|
||||
case 3 : commInfoId = 45; break; //小程序id
|
||||
}
|
||||
config.setAppId(commonInfoService.findOne(commInfoId).getValue());
|
||||
config.setKey(commonInfoService.findOne(75).getValue());
|
||||
config.setMchId(commonInfoService.findOne(76).getValue());
|
||||
WXPay wxpay = new WXPay(config);
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("appid", config.getAppID());
|
||||
data.put("mch_id", config.getMchID());
|
||||
data.put("nonce_str", WXPayUtil.generateNonceStr());
|
||||
try{
|
||||
data.put("sign", WXPayUtil.generateSignature(data, config.getKey(), WXPayConstants.SignType.MD5));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
data.put("out_trade_no", orders.getOrdersNo()); //订单号,支付单号一致
|
||||
data.put("out_refund_no", orders.getOrdersNo()); //退款单号,同一笔用不同的退款单号
|
||||
double total_fee = 0.00;
|
||||
data.put("total_fee", new Double(orders.getPayMoney().doubleValue()*100).intValue()+""); //1块等于微信支付传入100);
|
||||
data.put("refund_fee", new Double(orders.getPayMoney().doubleValue()*100).intValue()+""); //1块等于微信支付传入100);
|
||||
//使用官方API退款
|
||||
try{
|
||||
Map<String, String> response = wxpay.refund(data);
|
||||
if ("SUCCESS".equals(response.get("return_code"))) {//主要返回以下5个参数
|
||||
System.err.println("退款成功");
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.info("返回");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
77
src/main/java/com/sqx/modules/pay/utils/DYSign.java
Normal file
77
src/main/java/com/sqx/modules/pay/utils/DYSign.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.sqx.modules.pay.utils;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DYSign {
|
||||
|
||||
public static void main(String []args) {
|
||||
// 请求时间戳
|
||||
long timestamp = System.currentTimeMillis()/1000L;
|
||||
// 开发者填入自己的小程序app_id
|
||||
String appId = "testAppId";
|
||||
// 随机字符串
|
||||
String nonceStr = UUID.randomUUID().toString();
|
||||
// 应用公钥版本,每次重新上传公钥后需要更新,可通过「开发管理-开发设置-密钥设置」处获取
|
||||
String keyVersion = "1";
|
||||
// 应用私钥,用于加签 重要:1.测试时请修改为开发者自行生成的私钥;2.请勿将示例密钥用于生产环境;3.建议开发者不要将私钥文本写在代码中
|
||||
String privateKeyStr = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCZSHNcFfthd/bV\nYexEJWOBVEjjDcXjfr1fYevuraNFfMmLPKV836BbvCiUSWHzJYEpkJ934e/j28NB\nEcEbPDLiGlLTd6AVwR22TkUwpLr41oQprz0HKFwhVPZ0HQCGIv0pVMA53TFSitIq\niqbNLmgm5yzSNqNy1t/0X/RfqEtA6Eoxw9u/Sx57i+pBFuLlZYanlm57+b7t1khg\n9JHvF0ulo7DScyJ4qgrD7oQf0RIQB0rqCFIeYuYO1cfvnxb9x4DPodEyVoAM4i9Y\ndFop9ZHt73W/icuLku/P8/G1+arzB5b7S1S3ky5/KdS8AEA9Ww5czZcdf9Jgm2S6\nRymjFGjzAgMBAAECggEBAIryGNgdePyWcSJmHHR9a+CdFWD0aDBa/7CJpAN8VKc1\ngcB8Xgp+7+6X9jTM/EQa+CVEWrmiDgF/gVPnkyNsAzff4rqcEnoFzzglZSS9/lp4\nod7jYa+uTy1LxgflDkeJSfEASStqrT4EZpR3kNInQfQZ1BBNxQXhb6smm+9mL6kK\nQJjAqBgEqtUAmNv0GnH89ZPPgZuIZeeL4cb4BhMEoa5MBnI+HDf07cN1nECQXRJl\nHU/iyhAPfP7RpO8O9KGDEDE36qebu0Cu4yUjWANXiqECFv93sQzONotkl3VPealv\nXM+jzGT7YdgHo/t3QKE8flMBo/XUzGTqi8j5AOXiaBkCgYEAylKVtjQMYgg4qMwd\n9Je+KZ9qL6QVHCsB2NPUt8N99oj70efsG4aGaEAadr8meNhIJ5lpoK+FXqSBIbbD\nS/xeOVI3XoMx/EdKLw/ZNi87G/EHYK9z7Fr3W7q8DFXe2hZ/ojFXC/aaBanjVVBK\n/6RfPzXfnx+vGX/t1FhcLC+yQD8CgYEAwfMtrXfH+3dW77dxXT/CTFJVs/o1K2qb\nepnQ6A33KMHPLBtPZZ6z5rzIO7OMSNItOTXTEoRXHmOKc5FtXGtbCvGSRByb6FgD\nWG3p2Bp2sZLuJBzXmLbSnEbHTNHM6uTgxNgWAh8pYpjPY8xF7BqYz2rGT47OPBmc\ntRzDjnzjak0CgYAqkM1mk/S2+zvQZ4E14GblouBYPZEjZ/jvgUGTl9F8eL1iIAUQ\nlXDZpgLrULPrYLVtf101rTfF/Z4dVbIo3mOEc8OqYre1d9onpJHyUGWDL2Z59O/S\nniDEb7j4b2h/QZSArxi9L5if8GofnNDqj85qIg92Dthr6PpEXoKl2TMLSQKBgFzQ\nBHHYukiqSV4ZyRQ4qMBhPkYMXFlUgObgqMoDtN06MewHfa1BjxHCEYgQWfeXLLEO\nAt3/mrkeJWk8lLr/XOgVxkr17d34EFHG93rE3zwG9hMuAjZAdvT2IfWvCIL32GAa\nkB2fz+ww+D3nySY9bBcGH7R+wE6eaxF4nFSZizKZAoGBAJzuaWCnVK0djfgvUsjm\nGUtyDvgyREcpAsXvES1pB2NLVeEUxm0uRtj6k4DhCv3rJfUwfMr0+sa9NUnXuaSR\nVqLYvAD8bNPKXwn7ymzQ7WioCqmZuUhLnQRppkjhfQGKLH0MnMw9Xh9FwJ9kzGNE\nUnTEhaaHsoaHMlLlRET32gyG".replace("\n","");
|
||||
// 生成好的data
|
||||
String data = "{\"skuList\":[{\"skuId\":\"1\",\"price\":9999,\"quantity\":1,\"title\":\"标题\",\"imageList\":[\"https://dummyimage.com/234x60\"],\"type\":401,\"tagGroupId\":\"idxxx\"}],\"outOrderNo\":\"1213\",\"totalAmount\":9999,\"limitPayWayList\":[],\"payExpireSeconds\":3000,\"orderEntrySchema\":{\"path\":\"page/index/index\",\"params\":\"{\\\"poi\\\":\\\"6601248937917548558\\\",\\\"aweme_useTemplate\\\":1}\"}}";
|
||||
|
||||
String byteAuthorization = getByteAuthorization(privateKeyStr, data, appId, nonceStr, timestamp, keyVersion);
|
||||
System.out.println(byteAuthorization);
|
||||
}
|
||||
|
||||
public static String getByteAuthorization(String privateKeyStr, String data, String appId, String nonceStr, long timestamp, String keyVersion) {
|
||||
String byteAuthorization = "";
|
||||
try {
|
||||
// 生成签名
|
||||
String signature = getSignature(privateKeyStr, "POST", "/requestOrder", timestamp, nonceStr, data);
|
||||
// 构造byteAuthorization
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SHA256-RSA2048 ").
|
||||
append("appid=").append(appId).append(",").
|
||||
append("nonce_str=").append(nonceStr).append(",").
|
||||
append("timestamp=").append(timestamp).append(",").
|
||||
append("key_version=").append(keyVersion).append(",").
|
||||
append("signature=").append(signature);
|
||||
byteAuthorization = sb.toString();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
return byteAuthorization;
|
||||
}
|
||||
|
||||
public static String getSignature(String privateKeyStr, String method, String uri, long timestamp, String nonce, String data) throws Exception {
|
||||
String rawStr = method + "\n" +
|
||||
uri + "\n" +
|
||||
timestamp + "\n" +
|
||||
nonce + "\n" +
|
||||
data + "\n";
|
||||
Signature sign = Signature.getInstance("SHA256withRSA");
|
||||
sign.initSign(string2PrivateKey(privateKeyStr));
|
||||
sign.update(rawStr.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(sign.sign());
|
||||
}
|
||||
|
||||
public static PrivateKey string2PrivateKey(String privateKeyStr) {
|
||||
PrivateKey prvKey = null;
|
||||
try {
|
||||
byte[] privateBytes = Base64.getDecoder().decode(privateKeyStr);
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
prvKey = keyFactory.generatePrivate(keySpec);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return prvKey;
|
||||
}
|
||||
}
|
||||
|
||||
128
src/main/java/com/sqx/modules/pay/utils/DouYinSign.java
Normal file
128
src/main/java/com/sqx/modules/pay/utils/DouYinSign.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package com.sqx.modules.pay.utils;
|
||||
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DouYinSign {
|
||||
/**
|
||||
* 担保支付请求不参与签名参数
|
||||
* app_id 小程序appID
|
||||
* thirdparty_id 代小程序进行该笔交易调用的第三方平台服务商id
|
||||
* sign 签名
|
||||
* other_settle_params 其他分账方参数
|
||||
*
|
||||
* Guaranteed payment requests do not participate in signature parameters
|
||||
* app_id Applets appID
|
||||
* thirdparty_id The id of the third-party platform service provider that calls the transaction on behalf of the Applets
|
||||
* sign sign
|
||||
* other_settle_params Other settle params
|
||||
*/
|
||||
public final static List<String> REQUEST_NOT_NEED_SIGN_PARAMS = Arrays.asList("app_id", "thirdparty_id", "sign", "other_settle_params");
|
||||
|
||||
/**
|
||||
* 支付密钥值,需要替换为自己的密钥(完成进件后,开发者可在字节开放平台-【某小程序】-【功能】-【支付】-【担保交易设置】中查看支付系统秘钥 SALT)
|
||||
*
|
||||
* Payment key value, you need to replace it with your own key
|
||||
*/
|
||||
|
||||
/**
|
||||
* RequestSign 担保支付请求签名算法
|
||||
* @param paramsMap {@code Map<String, Object>} 所有的请求参数
|
||||
* @return:签名字符串
|
||||
*
|
||||
* RequestSign Guaranteed payment request signature algorithm
|
||||
* @param paramsMap {@code Map<String, Object>} all request parameters
|
||||
* @return: Signature string
|
||||
*/
|
||||
public static String requestSign(Map<String, Object> paramsMap,String SALT) {
|
||||
List<String> paramsArr = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (REQUEST_NOT_NEED_SIGN_PARAMS.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
String value = entry.getValue().toString();
|
||||
|
||||
value = value.trim();
|
||||
if (value.startsWith("\"") && value.endsWith("\"") && value.length() > 1) {
|
||||
value = value.substring(1, value.length() - 1);
|
||||
}
|
||||
value = value.trim();
|
||||
if (value.equals("") || value.equals("null")) {
|
||||
continue;
|
||||
}
|
||||
paramsArr.add(value);
|
||||
}
|
||||
paramsArr.add(SALT);
|
||||
Collections.sort(paramsArr);
|
||||
StringBuilder signStr = new StringBuilder();
|
||||
String sep = "";
|
||||
for (String s : paramsArr) {
|
||||
signStr.append(sep).append(s);
|
||||
sep = "&";
|
||||
}
|
||||
return md5FromStr(signStr.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* CallbackSign 担保支付回调签名算法
|
||||
* @param params {@code List<String>} 所有字段(验证时注意不包含 sign 签名本身,不包含空字段与 type 常量字段)内容与平台上配置的 token
|
||||
* @return:签名字符串
|
||||
*
|
||||
* CallbackSign Guaranteed payment callback signature algorithm
|
||||
* @param params {@code List<String>} The content of all fields (note that the sign signature itself is not included during verification, and does not include empty fields and type constant fields) content and the token configured on the platform
|
||||
* @return: signature string
|
||||
*/
|
||||
public static String callbackSign(List<String> params) {
|
||||
try {
|
||||
String concat = params.stream().sorted().collect(Collectors.joining(""));
|
||||
byte[] arrayByte = concat.getBytes(StandardCharsets.UTF_8);
|
||||
MessageDigest mDigest = MessageDigest.getInstance("SHA1");
|
||||
byte[] digestByte = mDigest.digest(arrayByte);
|
||||
|
||||
StringBuffer signBuilder = new StringBuffer();
|
||||
for (byte b : digestByte) {
|
||||
signBuilder.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return signBuilder.toString();
|
||||
} catch (Exception exp) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* md5FromStr md5算法对该字符串计算摘要
|
||||
* @param inStr {@code String} 需要签名的字符串
|
||||
* @return:签名字符串
|
||||
*
|
||||
* md5FromStr The md5 algorithm computes a digest of the string
|
||||
* @param inStr {@code String} String to be signed
|
||||
* @return: signature string
|
||||
*/
|
||||
private static String md5FromStr(String inStr) {
|
||||
MessageDigest md5;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
|
||||
byte[] byteArray = inStr.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuilder hexValue = new StringBuilder();
|
||||
for (byte md5Byte : md5Bytes) {
|
||||
int val = ((int) md5Byte) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
}
|
||||
|
||||
112
src/main/java/com/sqx/modules/pay/utils/IosVerify.java
Normal file
112
src/main/java/com/sqx/modules/pay/utils/IosVerify.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.sqx.modules.pay.utils;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName: IosVerify
|
||||
* @Description:Apple Pay
|
||||
*/
|
||||
public class IosVerify {
|
||||
|
||||
private static class TrustAnyTrustManager implements X509TrustManager {
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[] {};
|
||||
}
|
||||
}
|
||||
|
||||
private static class TrustAnyHostnameVerifier implements HostnameVerifier {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 沙盒地址
|
||||
*/
|
||||
private static final String url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt";
|
||||
/**
|
||||
* 线上地址
|
||||
*/
|
||||
private static final String url_verify = "https://buy.itunes.apple.com/verifyReceipt";
|
||||
|
||||
/**
|
||||
* 苹果服务器验证
|
||||
*
|
||||
* @param receipt
|
||||
* 账单
|
||||
* @url 要验证的地址
|
||||
* @return null 或返回结果 沙盒 https://sandbox.itunes.apple.com/verifyReceipt
|
||||
*
|
||||
*/
|
||||
public static String buyAppVerify(String receipt,Integer way) {
|
||||
//环境判断 线上/开发环境用不同的请求链接
|
||||
String url = url_verify;
|
||||
if(way==2){
|
||||
url = url_sandbox;
|
||||
}
|
||||
|
||||
try {
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
|
||||
URL console = new URL(url);
|
||||
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
||||
conn.setSSLSocketFactory(sc.getSocketFactory());
|
||||
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("content-type", "text/json");
|
||||
conn.setRequestProperty("Proxy-Connection", "Keep-Alive");
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
BufferedOutputStream hurlBufOus = new BufferedOutputStream(conn.getOutputStream());
|
||||
|
||||
String str = String.format(Locale.CHINA, "{\"receipt-data\":\"" + receipt + "\"}");
|
||||
hurlBufOus.write(str.getBytes());
|
||||
hurlBufOus.flush();
|
||||
|
||||
InputStream is = conn.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line = null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用BASE64加密
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String getBASE64(String str) {
|
||||
byte[] b = str.getBytes();
|
||||
String s = null;
|
||||
if (b != null) {
|
||||
s = new sun.misc.BASE64Encoder().encode(b);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user