|
|
|
@ -1,25 +1,20 @@ |
|
|
|
package com.cyjd.rights.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alipay.api.AlipayApiException; |
|
|
|
import com.alipay.api.AlipayConstants; |
|
|
|
import com.alipay.api.CertAlipayRequest; |
|
|
|
import com.alipay.api.*; |
|
|
|
import com.alipay.api.internal.util.AlipaySignature; |
|
|
|
import com.alipay.api.response.AlipayTradePayResponse; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.cyjd.rights.beans.AliPayProperties; |
|
|
|
import com.cyjd.rights.beans.R; |
|
|
|
import com.cyjd.rights.beans.ResultCodeEnum; |
|
|
|
import com.cyjd.rights.business.service.*; |
|
|
|
import com.cyjd.rights.constant.AliPayConstant; |
|
|
|
import com.cyjd.rights.constant.EnumPeriodType; |
|
|
|
import com.cyjd.rights.dto.AliPayInOrderByAgreementDto; |
|
|
|
import com.cyjd.rights.dto.AliPaySignUpDto; |
|
|
|
import com.cyjd.rights.entity.AliPayOrderEntity; |
|
|
|
import com.cyjd.rights.entity.AliPaySigningOrderEntity; |
|
|
|
import com.cyjd.rights.entity.ConfigEntity; |
|
|
|
import com.cyjd.rights.enums.AliPayEnum; |
|
|
|
import com.cyjd.rights.result.FResult; |
|
|
|
import com.cyjd.rights.utils.EntityConvertUtil; |
|
|
|
import com.cyjd.rights.utils.OrderUtil; |
|
|
|
import com.cyjd.rights.vo.AliPayInOrderByAgreementReq; |
|
|
|
import com.cyjd.rights.vo.AliPayQueryPageSignReq; |
|
|
|
@ -27,15 +22,12 @@ import com.cyjd.rights.vo.AliPayTradeQueryReq; |
|
|
|
import com.cyjd.rights.vo.AliPayUserPageSignReq; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.extern.java.Log; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
@ -75,22 +67,15 @@ public class AliPayController { |
|
|
|
private AliPayProperties aliPayProperties; |
|
|
|
|
|
|
|
|
|
|
|
private CertAlipayRequest certAlipayRequest; |
|
|
|
|
|
|
|
private static String[] unicom = {"130", "131", "132", "140", "155", "156", "185", "186", "145", "171", "176", "175", "166"}; |
|
|
|
private static String[] mobileArray = {"134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "178", "182", "183", "184", "187", "188", "195", "198"}; |
|
|
|
private static String[] tel = {"133", "153", "177", "180", "181", "189", "173", "149", "199"}; |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
/* @PostConstruct |
|
|
|
public void init() { |
|
|
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); |
|
|
|
//设置文件地址
|
|
|
|
// if (isSkipSign) {
|
|
|
|
// aliPayProperties.setCertPath("D:\\daima\\hy\\ringback-q\\02Ypcl\\01Code\\01Plantform\\Server\\vrbt-client-controller\\src\\main\\resources\\config\\");
|
|
|
|
// } else {
|
|
|
|
// aliPayProperties.setCertPath("/home/ypcl/server-client/config/");
|
|
|
|
// }
|
|
|
|
certAlipayRequest.setServerUrl(AliPayConstant.serverUrl); |
|
|
|
certAlipayRequest.setAppId(aliPayProperties.getAppId()); |
|
|
|
certAlipayRequest.setPrivateKey(aliPayProperties.getPrivateKey()); |
|
|
|
@ -101,17 +86,21 @@ public class AliPayController { |
|
|
|
certAlipayRequest.setAlipayPublicCertPath(aliPayProperties.getCertPath() + "alipayCertPublicKey_RSA2.crt"); |
|
|
|
certAlipayRequest.setRootCertPath(aliPayProperties.getCertPath() + "alipayRootCert.crt"); |
|
|
|
this.certAlipayRequest = certAlipayRequest; |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "支付宝签约", notes = "前端先调用此接口,由服务端请求支付宝组装scheme地址,之后前端通过该地址唤起支付宝进行签约") |
|
|
|
@PostMapping("/signUp") |
|
|
|
public R signUp(@RequestBody AliPaySignUpDto signUpDto) { |
|
|
|
String price="19.9"; |
|
|
|
String price = "19.9"; |
|
|
|
//查询用户31天内是否已经有代扣成功的记录了
|
|
|
|
if (!aliPayOrderService.checkOpen(signUpDto.getMobile())) { |
|
|
|
return R.error(ResultCodeEnum.user_month_repeat_open); |
|
|
|
} |
|
|
|
//获取现在要推广的账号
|
|
|
|
ConfigEntity configEntity = configService.getOne(new QueryWrapper<ConfigEntity>().eq("config_name", "account")); |
|
|
|
String aliPayAccountName = configEntity.getConfigValue(); |
|
|
|
|
|
|
|
AliPayUserPageSignReq signReq = new AliPayUserPageSignReq(); |
|
|
|
signUpDto.setIsPage(true); |
|
|
|
signUpDto.setPeriod("31"); //设置天数
|
|
|
|
@ -128,7 +117,7 @@ public class AliPayController { |
|
|
|
periodRuleParams.setSingleAmount(signUpDto.getSingleAmount()); |
|
|
|
signReq.setPeriodRuleParams(periodRuleParams); |
|
|
|
//aliPayUserPageSignReq.setSignScene("INDUSTRY|DIGITAL_MEDIA");
|
|
|
|
String signUrl = aliPayService.signUp(signReq); |
|
|
|
String signUrl = aliPayService.signUp(signReq, aliPayAccountName); |
|
|
|
//保存签约订单
|
|
|
|
AliPaySigningOrderEntity aliPaySigningOrderEntity = new AliPaySigningOrderEntity(); |
|
|
|
aliPaySigningOrderEntity.setOrderId(agreementNo); |
|
|
|
@ -137,11 +126,12 @@ public class AliPayController { |
|
|
|
aliPaySigningOrderEntity.setLinkId(signUpDto.getLinkId()); |
|
|
|
aliPaySigningOrderEntity.setLinkName("推广名字"); //先定死
|
|
|
|
aliPaySigningOrderEntity.setOperatorsId(1); //先定死可能不要这个参数
|
|
|
|
aliPaySigningOrderEntity.setIsPage(signUpDto.getIsPage()?1:0); |
|
|
|
aliPaySigningOrderEntity.setIsPage(signUpDto.getIsPage() ? 1 : 0); |
|
|
|
aliPaySigningOrderEntity.setOrderName("优爱腾三方权益业务"); |
|
|
|
aliPaySigningOrderEntity.setPrice(price); |
|
|
|
aliPaySigningOrderEntity.setAliAccountName(aliPayAccountName); |
|
|
|
aliPaySigningOrderEntity.setBusinessType(1); |
|
|
|
if (signUpDto.getSendApiData()!=null&&!Objects.equals(signUpDto.getSendApiData(), "")) { |
|
|
|
if (signUpDto.getSendApiData() != null && !Objects.equals(signUpDto.getSendApiData(), "")) { |
|
|
|
aliPaySigningOrderEntity.setSendApiData(signUpDto.getSendApiData()); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(signUrl)) { |
|
|
|
@ -158,19 +148,19 @@ public class AliPayController { |
|
|
|
|
|
|
|
@ApiOperation(value = "支付宝签约状态查询", notes = "签约成功以后前端可调用此接口查询是否签约成功") |
|
|
|
@PostMapping("/querySign") |
|
|
|
public FResult<?> querySign(@RequestParam String externalAgreementNo) { |
|
|
|
public FResult<?> querySign(@RequestParam String externalAgreementNo,@RequestParam String accountName) { |
|
|
|
AliPayQueryPageSignReq aliPayQueryPageSignReq = new AliPayQueryPageSignReq(); |
|
|
|
aliPayQueryPageSignReq.setExternalAgreementNo(externalAgreementNo); |
|
|
|
boolean querySign = aliPayService.querySign(aliPayQueryPageSignReq); |
|
|
|
boolean querySign = aliPayService.querySign(aliPayQueryPageSignReq,accountName); |
|
|
|
return FResult.ok(querySign); |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "支付宝支付状态查询", notes = "代扣以后可调用此接口查询是否成功") |
|
|
|
@PostMapping("/queryOrder") |
|
|
|
public FResult<?> queryOrder(@RequestParam String outTradeNo) { |
|
|
|
public FResult<?> queryOrder(@RequestParam String outTradeNo,@RequestParam String accountName) { |
|
|
|
AliPayTradeQueryReq aliPayTradeQueryReq = new AliPayTradeQueryReq(); |
|
|
|
aliPayTradeQueryReq.setOutTradeNo(outTradeNo); |
|
|
|
boolean queryOrder = aliPayService.queryOrder(aliPayTradeQueryReq); |
|
|
|
boolean queryOrder = aliPayService.queryOrder(aliPayTradeQueryReq, accountName); |
|
|
|
return FResult.ok(queryOrder); |
|
|
|
} |
|
|
|
|
|
|
|
@ -212,6 +202,31 @@ public class AliPayController { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "支付退款", notes = "支付退款") |
|
|
|
@PostMapping("/alipayRefund") |
|
|
|
public void alipayRefund() throws AlipayApiException { |
|
|
|
// AliPayEnum aliPayEnum = AliPayEnum.getMessageEnum(inMap.get("app_id"));
|
|
|
|
// CertAlipayRequest certAlipayRequest = aliPayService.init(aliPayEnum.getAccountName());
|
|
|
|
// AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
|
|
|
// AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
|
// JSONObject bizContent = new JSONObject();
|
|
|
|
// bizContent.put("out_trade_no", "Y2023080420524534021000");
|
|
|
|
// bizContent.put("refund_amount", 0.1);
|
|
|
|
// bizContent.put("out_request_no", "HZ01RF001");
|
|
|
|
// //// 返回参数选项,按需传入
|
|
|
|
// //JSONArray queryOptions = new JSONArray();
|
|
|
|
// //queryOptions.add("refund_detail_item_list");
|
|
|
|
// //bizContent.put("query_options", queryOptions);
|
|
|
|
//
|
|
|
|
// request.setBizContent(bizContent.toString());
|
|
|
|
// AlipayTradeRefundResponse response = alipayClient.certificateExecute(request);
|
|
|
|
// if (response.isSuccess()) {
|
|
|
|
// System.out.println("调用成功");
|
|
|
|
// } else {
|
|
|
|
// System.out.println("调用失败");
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//@Scheduled(cron = "0 0 8,20 * * ?")
|
|
|
|
|
|
|
|
@ -296,9 +311,12 @@ public class AliPayController { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String signNotify(Map<String, String> inMap) { |
|
|
|
|
|
|
|
log.info("===========================我是签约回调============================"); |
|
|
|
//log.info("支付宝签约回调开始:request{}", JSON.toJSONString(inMap));
|
|
|
|
try { |
|
|
|
AliPayEnum aliPayEnum = AliPayEnum.getMessageEnum(inMap.get("app_id")); |
|
|
|
CertAlipayRequest certAlipayRequest = aliPayService.init(aliPayEnum.getAccountName()); |
|
|
|
//验签
|
|
|
|
boolean signVerified = AlipaySignature.certVerifyV1(inMap, certAlipayRequest.getAlipayPublicCertPath(), AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2); |
|
|
|
if (signVerified) { |
|
|
|
@ -323,7 +341,7 @@ public class AliPayController { |
|
|
|
|
|
|
|
//更新订单签约信息
|
|
|
|
AliPaySigningOrderEntity aliPaySigningOrder = aliPaySigningOrderService.getOne(new QueryWrapper<AliPaySigningOrderEntity>().eq("order_id", externalAgreementNo)); |
|
|
|
if (aliPaySigningOrder==null){ |
|
|
|
if (aliPaySigningOrder == null) { |
|
|
|
return "fail"; |
|
|
|
} |
|
|
|
aliPaySigningOrder.setAliUserId(alipayUserId); |
|
|
|
@ -345,13 +363,13 @@ public class AliPayController { |
|
|
|
aliPaySigningOrder.setStatus(1); |
|
|
|
//设置下次续费的时间
|
|
|
|
aliPaySigningOrder.setNextPayTime(LocalDateTime.now().plusDays(31)); |
|
|
|
log.info("支付宝签约修改成功订单"+aliPaySigningOrder+"================================"); |
|
|
|
log.info("支付宝签约修改成功订单" + aliPaySigningOrder + "================================"); |
|
|
|
boolean b = aliPaySigningOrderService.updateById(aliPaySigningOrder); |
|
|
|
log.info("支付宝签约修改结果:=========================================================="+b); |
|
|
|
log.info("支付宝签约修改结果:==========================================================" + b); |
|
|
|
|
|
|
|
//进行扣款
|
|
|
|
aliPayService.aliPayTradePayByAgreement(payInOrderByAgreementReq,aliPaySigningOrder); |
|
|
|
}else { |
|
|
|
aliPayService.aliPayTradePayByAgreement(payInOrderByAgreementReq, aliPaySigningOrder,certAlipayRequest); |
|
|
|
} else { |
|
|
|
//修改订单状态为失败
|
|
|
|
aliPaySigningOrder.setStatus(0); |
|
|
|
aliPaySigningOrderService.updateById(aliPaySigningOrder); |
|
|
|
@ -402,8 +420,10 @@ public class AliPayController { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String agreementNotify(@RequestBody Map<String, String> inMap) { |
|
|
|
log.info("支付宝代扣回调开始:request{}"+JSON.toJSONString(inMap)); |
|
|
|
log.info("支付宝代扣回调开始:request{}" + JSON.toJSONString(inMap)); |
|
|
|
try { |
|
|
|
AliPayEnum aliPayEnum = AliPayEnum.getMessageEnum(inMap.get("app_id")); |
|
|
|
CertAlipayRequest certAlipayRequest = aliPayService.init(aliPayEnum.getAccountName()); |
|
|
|
//验签
|
|
|
|
boolean signVerified = AlipaySignature.certVerifyV1(inMap, certAlipayRequest.getAlipayPublicCertPath(), AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2); |
|
|
|
if (signVerified) { |
|
|
|
@ -442,18 +462,18 @@ public class AliPayController { |
|
|
|
//通知时间。通知的发送时间。格式为 yyyy-MM-dd HH:mm:ss。
|
|
|
|
String notifyTime = inMap.get("notify_time"); |
|
|
|
log.info("支付宝支付回调:" + inMap.toString()); |
|
|
|
log.info("outTradeNo====================="+outTradeNo); |
|
|
|
log.info("outTradeNo=====================" + outTradeNo); |
|
|
|
AliPaySigningOrderEntity aliPaySigningOrderEntity = aliPaySigningOrderService.getOne(new QueryWrapper<AliPaySigningOrderEntity>().eq("other_order_id", outTradeNo)); |
|
|
|
// for (AliPayOrderEntity aliPayOrderEntity : aliPayOrderService.list(new QueryWrapper<>())) {
|
|
|
|
// System.out.println(aliPayOrderEntity);
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (aliPaySigningOrderEntity==null){ |
|
|
|
if (aliPaySigningOrderEntity == null) { |
|
|
|
log.info("未查询到订单"); |
|
|
|
return "success"; |
|
|
|
} |
|
|
|
AliPayOrderEntity aliPayOrderEntity = new AliPayOrderEntity(); |
|
|
|
aliPayOrderEntity.setOrderId(System.currentTimeMillis()+""); |
|
|
|
aliPayOrderEntity.setOrderId(System.currentTimeMillis() + ""); |
|
|
|
aliPayOrderEntity.setOrderTime(LocalDateTime.now()); |
|
|
|
aliPayOrderEntity.setPrice(aliPaySigningOrderEntity.getPrice()); |
|
|
|
aliPayOrderEntity.setIsPage(aliPaySigningOrderEntity.getIsPage()); |
|
|
|
@ -464,26 +484,27 @@ public class AliPayController { |
|
|
|
aliPayOrderEntity.setBusinessType(aliPaySigningOrderEntity.getBusinessType()); |
|
|
|
aliPayOrderEntity.setLinkId(aliPaySigningOrderEntity.getLinkId()); |
|
|
|
aliPayOrderEntity.setLinkName(aliPaySigningOrderEntity.getLinkName()); |
|
|
|
aliPayOrderEntity.setAliAccountName(aliPaySigningOrderEntity.getAliAccountName()); |
|
|
|
aliPayOrderEntity.setOrderName("惠点联合会员"); |
|
|
|
if ("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) { |
|
|
|
aliPayOrderEntity.setStatus(1); |
|
|
|
aliPayOrderService.save(aliPayOrderEntity); |
|
|
|
log.info("支付订单保存成功"+aliPayOrderEntity); |
|
|
|
log.info("支付订单保存成功" + aliPayOrderEntity); |
|
|
|
//查看是否发送
|
|
|
|
if (sendSuccessMobileService.ifSendDataByType(aliPaySigningOrderEntity.getLinkId().toString(),outTradeNo)) { |
|
|
|
if (sendSuccessMobileService.ifSendDataByType(aliPaySigningOrderEntity.getLinkId().toString(), outTradeNo)) { |
|
|
|
//回传 1161张敏渠道
|
|
|
|
if (1161==aliPaySigningOrderEntity.getLinkId()){ |
|
|
|
if (1161 == aliPaySigningOrderEntity.getLinkId()) { |
|
|
|
//回传成功数据
|
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getMobile(),"zm",outTradeNo); |
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getMobile(), "zm", outTradeNo); |
|
|
|
} |
|
|
|
//回传 1160推啊渠道
|
|
|
|
if (1160==aliPaySigningOrderEntity.getLinkId()){ |
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getSendApiData(),"tuia",outTradeNo); |
|
|
|
if (1160 == aliPaySigningOrderEntity.getLinkId()) { |
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getSendApiData(), "tuia", outTradeNo); |
|
|
|
} |
|
|
|
|
|
|
|
//回传 1162赤金渠道
|
|
|
|
if (1162==aliPaySigningOrderEntity.getLinkId()){ |
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getSendApiData(),"cj",outTradeNo); |
|
|
|
if (1162 == aliPaySigningOrderEntity.getLinkId()) { |
|
|
|
sendSuccessMobileService.sendSuccessMobile(aliPaySigningOrderEntity.getSendApiData(), "cj", outTradeNo); |
|
|
|
} |
|
|
|
} |
|
|
|
// if (b){
|
|
|
|
@ -495,7 +516,7 @@ public class AliPayController { |
|
|
|
} |
|
|
|
aliPayOrderEntity.setStatus(0); |
|
|
|
aliPayOrderService.save(aliPayOrderEntity); |
|
|
|
log.info("支付开通失败订单保存成功"+aliPayOrderEntity); |
|
|
|
log.info("支付开通失败订单保存成功" + aliPayOrderEntity); |
|
|
|
|
|
|
|
} |
|
|
|
} catch (AlipayApiException e) { |
|
|
|
|