com.zopen.wechat.pay.dto.AppPayClientDto Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zopen-ato-starter Show documentation
Show all versions of zopen-ato-starter Show documentation
Alibaba Tencent And Others For Spring Boot.
package com.zopen.wechat.pay.dto;
import com.zopen.wechat.pay.util.SignUtil;
import java.util.Map;
import java.util.TreeMap;
/**
* 统一下单后,需要传给 APP 的内容
*
* @author [email protected]
* @since 2020/3/19
*/
public class AppPayClientDto {
private String appid;
// 商户号
private String partnerid;
private String prepayid;
private String packageValue;
private String noncestr;
private String timestamp;
private String sign;
public static AppPayClientDto formAppPayResponse(PayResponse appPayResponse, String appKey) {
if (appPayResponse == null || !appPayResponse.success()) {
return null;
}
AppPayClientDto dto = new AppPayClientDto();
dto.setAppid(appPayResponse.getAppid());
dto.setPartnerid(appPayResponse.getMch_id());
dto.setPrepayid(appPayResponse.getPrepay_id());
dto.setPackageValue("Sign=WXPay");
dto.setNoncestr(appPayResponse.getNonce_str());
dto.setTimestamp(String.valueOf((int) (System.currentTimeMillis() / 1000)));
Map treeMap = new TreeMap<>();
treeMap.put("appid", dto.getAppid());
treeMap.put("partnerid", dto.getPartnerid());
treeMap.put("prepayid", dto.getPrepayid());
treeMap.put("package", dto.getPackageValue());
treeMap.put("noncestr", dto.getNoncestr());
treeMap.put("timestamp", dto.getTimestamp());
String sign = SignUtil.sign(treeMap, appKey);
dto.setSign(sign);
return dto;
}
@Override
public String toString() {
return "AppPayClientDto{" +
"appid='" + appid + '\'' +
", partnerid='" + partnerid + '\'' +
", prepayid='" + prepayid + '\'' +
", packageValue='" + packageValue + '\'' +
", noncestr='" + noncestr + '\'' +
", timestamp='" + timestamp + '\'' +
", sign='" + sign + '\'' +
'}';
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getPartnerid() {
return partnerid;
}
public void setPartnerid(String partnerid) {
this.partnerid = partnerid;
}
public String getPrepayid() {
return prepayid;
}
public void setPrepayid(String prepayid) {
this.prepayid = prepayid;
}
public String getPackageValue() {
return packageValue;
}
public void setPackageValue(String packageValue) {
this.packageValue = packageValue;
}
public String getNoncestr() {
return noncestr;
}
public void setNoncestr(String noncestr) {
this.noncestr = noncestr;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
}