改造租户
This commit is contained in:
parent
525ad3d6db
commit
79cb33cf13
@ -0,0 +1,62 @@
|
|||||||
|
package com.wzj.soopin.order.wechat;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "wechat")
|
||||||
|
@Component("WechatPayData")
|
||||||
|
public class WechatPayData {
|
||||||
|
|
||||||
|
/** 商户号 */
|
||||||
|
public static String appId;
|
||||||
|
public static String secret;
|
||||||
|
public static String merchantId;
|
||||||
|
/** 商户API私钥路径 */
|
||||||
|
public static String privateKeyPath;
|
||||||
|
/** 商户证书序列号 */
|
||||||
|
public static String merchantSerialNumber;
|
||||||
|
/** 商户APIV3密钥 */
|
||||||
|
public static String apiV3key;
|
||||||
|
public static String notifyUrl;
|
||||||
|
|
||||||
|
public static String miniProgramAppId;
|
||||||
|
public static String miniProgramSecret;
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
WechatPayData.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
WechatPayData.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchantId(String merchantId) {
|
||||||
|
WechatPayData.merchantId = merchantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateKeyPath(String privateKeyPath) {
|
||||||
|
WechatPayData.privateKeyPath = privateKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchantSerialNumber(String merchantSerialNumber) {
|
||||||
|
WechatPayData.merchantSerialNumber = merchantSerialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiV3key(String apiV3key) {
|
||||||
|
WechatPayData.apiV3key = apiV3key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotifyUrl(String notifyUrl) {
|
||||||
|
WechatPayData.notifyUrl = notifyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMiniProgramAppId(String miniProgramAppId) {
|
||||||
|
WechatPayData.miniProgramAppId = miniProgramAppId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMiniProgramSecret(String miniProgramSecret) {
|
||||||
|
WechatPayData.miniProgramSecret = miniProgramSecret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package com.wzj.soopin.order.wechat;
|
||||||
|
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||||
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse;
|
||||||
|
import com.wechat.pay.java.service.refund.RefundService;
|
||||||
|
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||||
|
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||||
|
import com.wechat.pay.java.service.refund.model.Refund;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@ConditionalOnProperty(prefix = "wechat", name = "enabled", havingValue = "true")
|
||||||
|
public class WechatPayService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JsapiService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RefundService refundService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jsapi下单
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @param desc 订单描述
|
||||||
|
* @param totalAmount 总金额,单位:分
|
||||||
|
* @param openId 用户openid
|
||||||
|
* @return prepay_id
|
||||||
|
*/
|
||||||
|
public String jsapiPay(String orderNo,String desc,Integer totalAmount,String openId, Long memberId,String appId){
|
||||||
|
PrepayRequest prepayRequest = new PrepayRequest();
|
||||||
|
prepayRequest.setAppid(appId);
|
||||||
|
prepayRequest.setMchid(WechatPayData.merchantId);
|
||||||
|
prepayRequest.setDescription(desc);
|
||||||
|
prepayRequest.setOutTradeNo(orderNo);
|
||||||
|
prepayRequest.setAttach(String.valueOf(memberId));
|
||||||
|
prepayRequest.setNotifyUrl(WechatPayData.notifyUrl);
|
||||||
|
Amount amount = new Amount();
|
||||||
|
amount.setTotal(totalAmount);
|
||||||
|
prepayRequest.setAmount(amount);
|
||||||
|
Payer payer = new Payer();
|
||||||
|
payer.setOpenid(openId);
|
||||||
|
prepayRequest.setPayer(payer);
|
||||||
|
PrepayResponse response = service.prepay(prepayRequest);
|
||||||
|
return response.getPrepayId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Refund refundPay(String refundId,String payId,String notifyUrl,Long refundAmount, Long totalAmount,String reason) {
|
||||||
|
//请求参数
|
||||||
|
CreateRequest request = new CreateRequest();
|
||||||
|
request.setReason(reason);
|
||||||
|
//设置退款金额 根据自己的实际业务自行填写
|
||||||
|
AmountReq amountReq = new AmountReq();
|
||||||
|
amountReq.setRefund(refundAmount);
|
||||||
|
amountReq.setTotal(totalAmount);
|
||||||
|
amountReq.setCurrency("CNY");
|
||||||
|
request.setAmount(amountReq);
|
||||||
|
//支付成功后回调回来的transactionId 按照实际情况填写
|
||||||
|
request.setOutTradeNo(payId);
|
||||||
|
//支付成功后回调回来的transactionId 按照实际情况填写
|
||||||
|
request.setOutRefundNo(refundId);
|
||||||
|
//退款成功的回调地址
|
||||||
|
request.setNotifyUrl(notifyUrl);
|
||||||
|
//发起请求,申请退款
|
||||||
|
return refundService.create(request);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user