package com.duke.learn.weixinpay.util;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import com.duke.learn.weixinpay.util.WxPayApi.TradeType;
public class WxPayApiConfig implements Serializable {
private static final long serialVersionUID = -6447075676732210047L;
private String appId;
private String mchId;
private String subAppId;
private String subMchId;
private String paternerKey;
private String nonceStr;
private String body;
private String attach;
private String transactionId;
private String outTradeNo;
private String totalFee;
private String spbillCreateIp;
private String notifyUrl;
private TradeType tradeType;
private String openId;
private String subOpenId;
private String authCode;
private String sceneInfo;
private String planId;
private String contractCode;
private String requestSerial;
private String contractDisplayAccount;
private String version;
private String timestamp;
private String returnApp;
private String returnWeb;
private String contractNotifyUrl;
private String contractId;
private PayModel payModel;
/**
* 分别对应商户模式、服务商模式
*/
public static enum PayModel {
BUSINESSMODEL, SERVICEMODE
}
private WxPayApiConfig() {
}
public static WxPayApiConfig New() {
return new WxPayApiConfig();
}
/**
* 构建请求参数
*
* @return Map<String, String>
*/
public Map<String, String> build() {
Map<String, String> map = new HashMap<String, String>();
if (getPayModel().equals(PayModel.SERVICEMODE)) {
//服务商上模式
map.put("sub_mch_id", getSubMchId());
if (StrKit.notBlank(getSubAppId())) {
map.put("sub_appid", subAppId);
}
}
/**
* openId和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid
*/
if (getTradeType().equals(TradeType.JSAPI)) {
//公众号支付
if (StrKit.notBlank(getSubAppId())) {
map.put("sub_appid", subAppId);
map.put("sub_openid", getSubOpenId());
} else {
map.put("openid", getOpenId());
}
}
/**
* H5支付必填scene_info
*/
if (getTradeType().equals(TradeType.MWEB)) {
if (StrKit.isBlank(getSceneInfo())) {
throw new IllegalArgumentException("微信H5支付 scene_info 不能同时为空");
}
map.put("scene_info", getSceneInfo());
}
map.put("appid", getAppId());
map.put("mch_id", getMchId());
map.put("nonce_str", getNonceStr());
map.put("body", getBody());
map.put("out_trade_no", getOutTradeNo());
map.put("total_fee", getTotalFee());
map.put("spbill_create_ip", getSpbillCreateIp());
map.put("trade_type", getTradeType().name());
map.put("attach", getAttach());
if (getTradeType().equals(TradeType.MICROPAY)) {
map.put("auth_code", getAuthCode());
map.remove("trade_type");
} else {
map.put("notify_url", getNotifyUrl());
}
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
return map;
}
/**
* 构建查询订单参数
*
* @return <Map<String, String>>
*/
public Map<String, String> orderQueryBuild() {
Map<String, String> map = new HashMap<String, String>();
if (getPayModel().equals(PayModel.SERVICEMODE)) {
//服务商上模式
map.put("sub_mch_id", getSubMchId());
map.put("sub_appid", getSubAppId());
}
map.put("appid", getAppId());
map.put("mch_id", getMchId());
if (StrKit.notBlank(getTransactionId())) {
map.put("transaction_id", getTransactionId());
} else {
if (StrKit.isBlank(getOutTradeNo())) {
throw new IllegalArgumentException("out_trade_no,transaction_id 不能同时为空");
}
map.put("out_trade_no", getOutTradeNo());
}
map.put("nonce_str", String.valueOf(System.currentTimeMillis()));
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
return map;
}
/**
* 构建申请签约Map
*
* @return 申请签约Map
* @throws UnsupportedEncodingException
*/
public Map<String, String> entrustwebBuild() throws UnsupportedEncodingException {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", getAppId());
map.put("mch_id", getMchId());
map.put("plan_id", getPlanId());
map.put("contract_code", getContractCode());
map.put("request_serial", getRequestSerial());
map.put("contract_display_account", getContractDisplayAccount());
map.put("notify_url", getNotifyUrl());
map.put("version", getVersion());
map.put("timestamp", getTimestamp());
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
for (Entry<String, String> param : map.entrySet()) {
String key = param.getKey();
String value = param.getValue();
value = PaymentKit.urlEncode(value);
map.put(key, value);
}
return map;
}
/**
* 构建支付中签约Map
*
* @return 支付中签约Map
*/
public Map<String, String> contractorderBuild() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", getAppId());
map.put("mch_id", getMchId());
map.put("contract_appid", getAppId());
map.put("contract_mchid", getMchId());
map.put("out_trade_no", getOutTradeNo());
map.put("nonce_str", getNonceStr());
map.put("body", getBody());
map.put("attach", getAttach());
map.put("notify_url", getNotifyUrl());
map.put("total_fee", getTotalFee());
map.put("spbill_create_ip", getSpbillCreateIp());
map.put("trade_type", getTradeType().name());
if (getTradeType().equals(TradeType.JSAPI)) {
map.put("openid", getOpenId());
}
map.put("plan_id", getPlanId());
map.put("contract_code", getContractCode());
map.put("request_serial", getRequestSerial());
map.put("contract_display_account", getContractDisplayAccount());
map.put("contract_notify_url", getContractNotifyUrl());
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
return map;
}
/**
* 构建查询签约关系的Map
*
* @return 查询签约关系的Map
*/
public Map<String, String> querycontractBuild() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", getAppId());
map.put("mch_id", getMchId());
if (StrKit.notBlank(getPlanId())) {
map.put("plan_id", getPlanId());
map.put("contract_code", getContractCode());
} else {
map.put("contract_id", getContractId());
}
map.put("version", getVersion());
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
return map;
}
/**
* 构建申请扣款的Map
*
* @return 申请扣款的Map
*/
public Map<String, String> pappayapplyBuild() {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", getAppId());
map.put("mch_id", getMchId());
map.put("nonce_str", getNonceStr());
map.put("body", getBody());
map.put("attach", getAttach());
map.put("out_trade_no", getOutTradeNo());
map.put("total_fee", getTotalFee());
map.put("spbill_create_ip", getSpbillCreateIp());
map.put("notify_url", getNotifyUrl());
map.put("trade_type", getTradeType().name());
map.put("contract_id", getContractId());
map.put("sign", PaymentKit.createSign(map, getPaternerKey()));
return map;
}
public String getAppId() {
if (StrKit.isBlank(appId))
throw new IllegalArgumentException("appId 未被赋值");
return appId;
}
public WxPayApiConfig setAppId(String appId) {
if (StrKit.isBlank(appId))
throw new IllegalArgumentException("appId 值不能为空");
this.appId = appId;
return this;
}
public String getMchId() {
if (StrKit.isBlank(mchId))
throw new IllegalArgumentException("mchId 未被赋值");
return mchId;
}
public WxPayApiConfig setMchId(String mchId) {
if (StrKit.isBlank(mchId))
throw new IllegalArgumentException("mchId 值不能为空");
this.mchId = mchId;
return this;
}
public String getSubAppId() {
return subAppId;
}
public WxPayApiConfig setSubAppId(String subAppId) {
if (StrKit.isBlank(subAppId))
throw new IllegalArgumentException("subAppId 值不能为空");
this.subAppId =
没有合适的资源?快使用搜索试试~ 我知道了~
springboot整合微信支付,拿来即用
共77个文件
class:31个
java:21个
html:4个
3星 · 超过75%的资源 需积分: 48 229 下载量 30 浏览量
2018-06-09
09:56:27
上传
评论 5
收藏 213KB ZIP 举报
温馨提示
只需要配置微信的必要参数,拿来即用 简单方便,前端用Thymeleaf整合,后台springboot
资源推荐
资源详情
资源评论
收起资源包目录
weixinpay.zip (77个子文件)
weixinpay
.gitignore 268B
.mvn
wrapper
maven-wrapper.jar 46KB
maven-wrapper.properties 110B
src
main
resources
templates
pay
pay.html 2KB
index.html 530B
static
js
jquery.js 94KB
weixinpay.js 2KB
application.properties 309B
java
com
duke
learn
weixinpay
util
PaymentKit.java 6KB
StringUtils.java 4KB
GsonUtils.java 896B
WxPayApiConfig.java 16KB
ResponseUtil.java 510B
StrKit.java 3KB
XmlHelper.java 6KB
WxPayApiConfigKit.java 2KB
DateKit.java 2KB
IOUtils.java 2KB
HttpUtils.java 14KB
HashKit.java 2KB
HttpKitExt.java 7KB
HttpKit.java 7KB
IpKit.java 830B
ClassUtils.java 478B
Charsets.java 357B
WxPayApi.java 16KB
web
WxPayAllController.java 12KB
WeixinpayApplication.java 312B
test
java
com
duke
learn
WeixinpayApplicationTests.java 334B
.classpath 1KB
mvnw 6KB
.settings
org.eclipse.wst.common.project.facet.core.xml 145B
org.eclipse.m2e.core.prefs 97B
org.eclipse.core.resources.prefs 155B
org.eclipse.jdt.core.prefs 243B
pom.xml 3KB
mvnw.cmd 5KB
target
classes
META-INF
MANIFEST.MF 316B
maven
com.duke
weixinpay
pom.properties 225B
pom.xml 3KB
com
duke
learn
WeixinpayApplication.class 714B
weixinpay
util
HttpKitExt.class 7KB
PaymentKit.class 7KB
GsonUtils.class 1KB
DateKit.class 3KB
HttpUtils$OkHttp3Delegate.class 9KB
HttpUtils$HttpKitDelegate.class 2KB
XmlHelper$XmlHelperHolder.class 984B
HttpUtils$OkHttpDelegate.class 9KB
Charsets.class 638B
HashKit.class 3KB
WxPayApi.class 10KB
StringUtils.class 5KB
IOUtils.class 2KB
StrKit.class 3KB
ResponseUtil.class 1KB
HttpKit.class 10KB
StringUtils$RandomType.class 1KB
IpKit.class 1KB
WxPayApiConfig.class 15KB
ClassUtils.class 742B
WxPayApiConfigKit.class 3KB
WxPayApiConfig$PayModel.class 1KB
HttpUtils$HttpDelegate.class 840B
XmlHelper.class 6KB
HttpUtils.class 3KB
HttpKit$TrustAnyHostnameVerifier.class 993B
HttpKit$TrustAnyTrustManager.class 1KB
WxPayApi$TradeType.class 1KB
web
WxPayAllController.class 12KB
templates
pay
pay.html 2KB
index.html 530B
static
js
jquery.js 94KB
weixinpay.js 2KB
application.properties 309B
test-classes
com
duke
learn
WeixinpayApplicationTests.class 633B
.project 1KB
共 77 条
- 1
资源评论
- 技术管理修行2019-05-26资源不错的
- 吴丁2019-01-14缺东西,部分东西可以参考。但是直接能用是不存在的。。。浪费12分
- u0101543802018-10-29还不知道能不能用
你的世界我不懂?
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功