package com.github.wxpay.sdk;
import com.github.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;
if (useSandbox) {
this.signType = SignType.MD5; // 沙箱环境
}
else {
this.signType = SignType.HMACSHA256;
}
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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目已完美集成支付宝扫码支付,导入项目后在zfbinfo.properties根据要求填写相对应的appid和密钥就可执行,项目包括sdk,和已经写好的demo以及前端展示二维码页面
资源推荐
资源详情
资源评论
收起资源包目录
Java集成支付宝扫码支付项目_支付宝刷脸支付官方奖励政策 (124个子文件)
AlipayFaceToFaceController.class 6KB
AlipayFaceToFaceController.class 6KB
AlipayFaceToFace.class 3KB
AlipayFaceToFace.class 3KB
ZFBFaceToFaceModel.class 3KB
ZFBFaceToFaceModel.class 3KB
TestTest.class 2KB
TestController.class 1KB
TestController.class 1KB
CommonUtils.class 1KB
CommonUtils.class 1KB
TestServiceImpl.class 688B
TestServiceImpl.class 688B
TestDao.class 256B
TestDao.class 256B
TestService.class 159B
TestService.class 159B
.classpath 2KB
video-js.css 46KB
video-js.css 46KB
AlipaQrcodePayment.html 3KB
AlipaQrcodePayment.html 3KB
videoTest.html 2KB
videoTest.html 2KB
index.html 450B
index.html 450B
alipay-sdk-java-4.10.209.ALL.jar 12.83MB
bcprov-jdk15on-1.62.jar 4.35MB
ojdbc6-11.2.0.3.jar 2.59MB
javaee-api-7.0.jar 1.84MB
spring-context-4.0.2.RELEASE.jar 951KB
spring-core-4.0.2.RELEASE.jar 938KB
mysql-connector-java-5.1.30.jar 932KB
jackson-mapper-asl-1.9.13.jar 762KB
mybatis-3.2.6.jar 696KB
spring-beans-4.0.2.RELEASE.jar 653KB
spring-web-4.0.2.RELEASE.jar 649KB
spring-webmvc-4.0.2.RELEASE.jar 645KB
mchange-commons-java-0.2.11.jar 592KB
javax.mail-1.5.0.jar 510KB
c3p0-0.9.5.2.jar 486KB
log4j-1.2.17.jar 478KB
spring-test-4.0.2.RELEASE.jar 437KB
spring-jdbc-4.0.2.RELEASE.jar 410KB
jstl-1.2.jar 405KB
fastjson-1.1.41.jar 350KB
spring-aop-4.0.2.RELEASE.jar 344KB
commons-codec-1.9.jar 258KB
spring-tx-4.0.2.RELEASE.jar 242KB
jackson-core-asl-1.9.13.jar 227KB
spring-expression-4.0.2.RELEASE.jar 200KB
commons-io-2.4.jar 181KB
spring-context-support-4.0.2.RELEASE.jar 132KB
commons-dbcp-1.2.2.jar 119KB
spring-oxm-4.0.2.RELEASE.jar 78KB
commons-fileupload-1.3.1.jar 67KB
activation-1.1.jar 62KB
commons-pool-1.3.jar 61KB
commons-logging-1.1.3.jar 61KB
mybatis-spring-1.2.2.jar 48KB
slf4j-api-1.7.7.jar 29KB
slf4j-log4j12-1.7.7.jar 9KB
aopalliance-1.0.jar 4KB
WXPay.java 26KB
WXPayReport.java 11KB
WXPayRequest.java 10KB
WXPayUtil.java 10KB
AlipayFaceToFaceController.java 8KB
AlipayFaceToFace.java 8KB
ZFBFaceToFaceModel.java 8KB
WXPayConstants.java 3KB
WXPayConfig.java 2KB
IWXPayDomain.java 1KB
WXPayXmlUtil.java 1KB
MyConfig.java 1KB
TestTest.java 1KB
WXPayExample.java 1KB
CommonUtils.java 930B
test2.java 867B
TestController.java 791B
TestServiceImpl.java 432B
TestDao.java 185B
TestService.java 116B
test_3.java 110B
test_two.java 103B
test.java 78B
video.js 2.12MB
video.js 2.12MB
videojs-http-streaming.js 875KB
videojs-http-streaming.js 875KB
jquery-1.11.2.min.js 94KB
jquery-1.11.2.min.js 94KB
jquery.qrcode.min.js 14KB
jquery.qrcode.min.js 14KB
videojs-http-streaming.min.js 7KB
videojs-http-streaming.min.js 7KB
ssm.log 398KB
MANIFEST.MF 101B
org.eclipse.jdt.core.prefs 488B
org.eclipse.core.resources.prefs 191B
共 124 条
- 1
- 2
蓝胖子哇
- 粉丝: 1w+
- 资源: 1
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 微信小程序源码 车源宝 二手车交易平台 源码下载
- 微信小程序源码 实现 城市切换 demo 根据城市首字母排序城市 选择城市 源码下载
- VMware7.0虚拟机硬盘无法编辑,无法连接到Profile-Driven Storage Service
- arm64内核的mongo镜像
- 基于stm32f103c单片机+MPU6050+0.96英寸OLED显示屏双柄遥控器硬件(原理图+PCB)工程文件.zip
- 整理的关于少儿编程的学习路径,以及如何在小升初,初升高和大学充分的利用起来编程经验的优势
- nhit完整源码+论文学习
- 足球比赛结果统计表2006-2011年大约28W场比赛
- 基于PHP+mysql的社区交流系统(源代码)
- yolov5,SSD 可能使用到的一些代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页