package com.example.jieyue.wxpay.sdk;
import com.example.jieyue.wxpay.sdk.WXPayConstants.SignType;
import java.util.HashMap;
import java.util.Map;
public class WXPay {
private WXPayConfig config;
private SignType signType;
private boolean autoReport;
private boolean useSandbox;
private String notifyUrl;
private WXPayRequest wxPayRequest;
public WXPay(final WXPayConfig config) throws Exception {
this(config, null, true, false);
}
public WXPay(final WXPayConfig config, final boolean autoReport) throws Exception {
this(config, null, autoReport, false);
}
public WXPay(final WXPayConfig config, final boolean autoReport, final boolean useSandbox) throws Exception{
this(config, null, autoReport, useSandbox);
}
public WXPay(final WXPayConfig config, final String notifyUrl) throws Exception {
this(config, notifyUrl, true, false);
}
public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport) throws Exception {
this(config, notifyUrl, autoReport, false);
}
public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport, final boolean useSandbox) throws Exception {
this.config = config;
this.notifyUrl = notifyUrl;
this.autoReport = autoReport;
this.useSandbox = useSandbox;
this.signType = SignType.MD5;
this.wxPayRequest = new WXPayRequest(config);
}
private void checkWXPayConfig() throws Exception {
if (this.config == null) {
throw new Exception("config is null");
}
if (this.config.getAppID() == null || this.config.getAppID().trim().length() == 0) {
throw new Exception("appid in config is empty");
}
if (this.config.getMchID() == null || this.config.getMchID().trim().length() == 0) {
throw new Exception("appid in config is empty");
}
if (this.config.getCertStream() == null) {
throw new Exception("cert stream in config is empty");
}
if (this.config.getWXPayDomain() == null){
throw new Exception("config.getWXPayDomain() is null");
}
if (this.config.getHttpConnectTimeoutMs() < 10) {
throw new Exception("http connect timeout is too small");
}
if (this.config.getHttpReadTimeoutMs() < 10) {
throw new Exception("http read timeout is too small");
}
}
/**
* 向 Map 中添加 appid、mch_id、nonce_str、sign_type、sign <br>
* 该函数适用于商户适用于统一下单等接口,不适用于红包、代金券接口
*
* @param reqData
* @return
* @throws Exception
*/
public Map<String, String> fillRequestData(Map<String, String> reqData) throws Exception {
reqData.put("appid", config.getAppID());
reqData.put("mch_id", config.getMchID());
reqData.put("nonce_str", WXPayUtil.generateNonceStr());
if (SignType.MD5.equals(this.signType)) {
reqData.put("sign_type", WXPayConstants.MD5);
}
else if (SignType.HMACSHA256.equals(this.signType)) {
reqData.put("sign_type", WXPayConstants.HMACSHA256);
}
reqData.put("sign", WXPayUtil.generateSignature(reqData, config.getKey(), this.signType));
return reqData;
}
/**
* 判断xml数据的sign是否有效,必须包含sign字段,否则返回false。
*
* @param reqData 向wxpay post的请求数据
* @return 签名是否有效
* @throws Exception
*/
public boolean isResponseSignatureValid(Map<String, String> reqData) throws Exception {
// 返回数据的签名方式和请求中给定的签名方式是一致的
return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), this.signType);
}
/**
* 判断支付结果通知中的sign是否有效
*
* @param reqData 向wxpay post的请求数据
* @return 签名是否有效
* @throws Exception
*/
public boolean isPayResultNotifySignatureValid(Map<String, String> reqData) throws Exception {
String signTypeInData = reqData.get(WXPayConstants.FIELD_SIGN_TYPE);
SignType signType;
if (signTypeInData == null) {
signType = SignType.MD5;
}
else {
signTypeInData = signTypeInData.trim();
if (signTypeInData.length() == 0) {
signType = SignType.MD5;
}
else if (WXPayConstants.MD5.equals(signTypeInData)) {
signType = SignType.MD5;
}
else if (WXPayConstants.HMACSHA256.equals(signTypeInData)) {
signType = SignType.HMACSHA256;
}
else {
throw new Exception(String.format("Unsupported sign_type: %s", signTypeInData));
}
}
return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), signType);
}
/**
* 不需要证书的请求
* @param urlSuffix String
* @param reqData 向wxpay post的请求数据
* @param connectTimeoutMs 超时时间,单位是毫秒
* @param readTimeoutMs 超时时间,单位是毫秒
* @return API返回数据
* @throws Exception
*/
public String requestWithoutCert(String urlSuffix, Map<String, String> reqData,
int connectTimeoutMs, int readTimeoutMs) throws Exception {
String msgUUID = reqData.get("nonce_str");
String reqBody = WXPayUtil.mapToXml(reqData);
String resp = this.wxPayRequest.requestWithoutCert(urlSuffix, msgUUID, reqBody, connectTimeoutMs, readTimeoutMs, autoReport);
return resp;
}
/**
* 需要证书的请求
* @param urlSuffix String
* @param reqData 向wxpay post的请求数据 Map
* @param connectTimeoutMs 超时时间,单位是毫秒
* @param readTimeoutMs 超时时间,单位是毫秒
* @return API返回数据
* @throws Exception
*/
public String requestWithCert(String urlSuffix, Map<String, String> reqData,
int connectTimeoutMs, int readTimeoutMs) throws Exception {
String msgUUID= reqData.get("nonce_str");
String reqBody = WXPayUtil.mapToXml(reqData);
String resp = this.wxPayRequest.requestWithCert(urlSuffix, msgUUID, reqBody, connectTimeoutMs, readTimeoutMs, this.autoReport);
return resp;
}
/**
* 处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。
* @param xmlStr API返回的XML格式数据
* @return Map类型数据
* @throws Exception
*/
public Map<String, String> processResponseXml(String xmlStr) throws Exception {
String RETURN_CODE = "return_code";
String return_code;
Map<String, String> respData = WXPayUtil.xmlToMap(xmlStr);
if (respData.containsKey(RETURN_CODE)) {
return_code = respData.get(RETURN_CODE);
}
else {
throw new Exception(String.format("No `return_code` in XML: %s", xmlStr));
}
if (return_code.equals(WXPayConstants.FAIL)) {
return respData;
}
else if (return_code.equals(WXPayConstants.SUCCESS)) {
if (this.isResponseSignatureValid(respData)) {
return respData;
}
else {
throw new Exception(String.format("Invalid sign value in XML: %s", xmlStr));
}
}
else {
throw new Exception(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
}
}
/**
* 作用:提交刷卡支付<br>
* 场景:刷卡支付
* @param reqData 向wxpay post的请求数据
* @return API返回数据
* @throws Exception
*/
public Map<String, String> microPay(Map<String, Stri
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot的轻量级单体架构购物商城网站设计源码
共659个文件
jpg:196个
java:109个
png:104个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 13 浏览量
2024-04-15
01:15:57
上传
评论
收藏 36.54MB ZIP 举报
温馨提示
基于SpringBoot的轻量级单体架构购物商城网站设计源码,该项目包含660个文件,主要文件类型有196个jpg图像文件,109个java源文件,以及104个png图像文件。此外,还包括63个javascript文件,40个css样式文件,以及36个html页面文件。该项目是一个基于SpringBoot开发的轻量级单体架构购物商城网站,分为用户、商户、后台三大模块。用户模块能够进行商品搜索浏览、在线下单、微信支付等功能;商户模块则可以对收益情况以及订单成交情况进行查看,并且可对商品进行上下架和增加删除等操作。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot的轻量级单体架构购物商城网站设计源码 (659个子文件)
mvnw.cmd 6KB
materialize.css 151KB
bootstrap.min.css 138KB
bootstrap.min.css 120KB
materialize.min.css 115KB
materialize.min.css 115KB
bootstrap.css 115KB
bootstrap.min.css 115KB
settings.css 72KB
animate.css 67KB
style.css 66KB
style.css 62KB
style-freedom.css 46KB
jquery-ui.css 34KB
font-awesome.css 34KB
settings-ie8.css 26KB
font-awesome.min.css 23KB
font.css 21KB
font-awesome.css 21KB
bootstrap-theme.min.css 19KB
custom-styles.css 15KB
cssCharts.css 10KB
monthly.css 8KB
normalize.css 8KB
responsive.css 7KB
style.css 7KB
style-responsive.css 6KB
main.css 6KB
dataTables.bootstrap.css 5KB
jquery.fancybox.css 5KB
owl.transitions.css 4KB
style.css 4KB
lightbox.css 4KB
style.css 2KB
meanmenu.min.css 2KB
owl.theme.css 2KB
minimal.css 1KB
owl.carousel.css 1KB
jqvmap.css 746B
morris-0.4.3.min.css 442B
morris.css 431B
fontawesome-webfont.eot 162KB
fontawesome-webfont.eot 75KB
fontawesome-webfont.eot 59KB
fontawesome-webfontd41d.eot 37KB
fontawesome-webfontba72.eot 37KB
Roboto-Thin.eot 21KB
Roboto-Medium.eot 21KB
Roboto-Regular.eot 21KB
Roboto-Bold.eot 20KB
Roboto-Light.eot 20KB
glyphicons-halflings-regulard41d.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
revicons.eot 12KB
loading.gif 450KB
[email protected] 14KB
fancybox_loading.gif 6KB
fancybox_loading.gif 6KB
loader2.gif 3KB
loader.gif 2KB
blank.gif 43B
blank.gif 43B
.gitignore 396B
index.html 126KB
index.html 29KB
index.html 17KB
index.html 15KB
index.html 15KB
index.html 14KB
index.html 13KB
model.html 13KB
index.html 13KB
index.html 12KB
index.html 12KB
index.html 12KB
index.html 11KB
index.html 10KB
index.html 9KB
index.html 9KB
index.html 9KB
index.html 7KB
index.html 7KB
index.html 7KB
index.html 7KB
role-access.html 6KB
index.html 6KB
model.html 5KB
index.html 5KB
model.html 5KB
index.html 5KB
index.html 4KB
index - Copy.html 4KB
index.html 4KB
index.html 4KB
error.html 2KB
wx.html 1KB
index.html 442B
alert.html 209B
footer.html 120B
共 659 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
沐知全栈开发
- 粉丝: 4771
- 资源: 3372
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功