新增Weixin4jSettings配置类
This commit is contained in:
@@ -14,6 +14,7 @@ import com.foxinmy.weixin4j.model.MediaItem;
|
||||
import com.foxinmy.weixin4j.model.MediaRecord;
|
||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||
import com.foxinmy.weixin4j.model.Pageable;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.mp.api.CustomApi;
|
||||
import com.foxinmy.weixin4j.mp.api.DataApi;
|
||||
import com.foxinmy.weixin4j.mp.api.GroupApi;
|
||||
@@ -21,7 +22,6 @@ import com.foxinmy.weixin4j.mp.api.HelperApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MassApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MediaApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MenuApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MpApi;
|
||||
import com.foxinmy.weixin4j.mp.api.NotifyApi;
|
||||
import com.foxinmy.weixin4j.mp.api.QrApi;
|
||||
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
||||
@@ -47,8 +47,8 @@ import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.mp.type.DatacubeType;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
import com.foxinmy.weixin4j.settings.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
@@ -80,45 +80,26 @@ public class WeixinProxy {
|
||||
private final DataApi dataApi;
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private String appId;
|
||||
private Weixin4jSettings settings;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinProxy() {
|
||||
this(MpApi.DEFAULT_TOKEN_STORAGER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的账号信息
|
||||
*
|
||||
* @param tokenStorager
|
||||
*/
|
||||
public WeixinProxy(TokenStorager tokenStorager) {
|
||||
this(MpApi.DEFAULT_WEIXIN_ACCOUNT.getId(), MpApi.DEFAULT_WEIXIN_ACCOUNT
|
||||
.getSecret(), tokenStorager);
|
||||
this(new Weixin4jSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appid
|
||||
* @param appsecret
|
||||
* @param settings
|
||||
* 配置信息
|
||||
* @see com.foxinmy.weixin4j.settings.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(String appid, String appsecret) {
|
||||
this(appid, appsecret, MpApi.DEFAULT_TOKEN_STORAGER);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appid
|
||||
* @param appsecret
|
||||
* @param tokenStorager
|
||||
*/
|
||||
public WeixinProxy(String appid, String appsecret,
|
||||
TokenStorager tokenStorager) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(appid, appsecret),
|
||||
tokenStorager));
|
||||
this.appId = appid;
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getTokenStorager()));
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,12 +124,12 @@ public class WeixinProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取appid
|
||||
* 获取微信账号信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAppId() {
|
||||
return this.appId;
|
||||
public WeixinAccount getWeixinAccount() {
|
||||
return this.settings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,8 +149,9 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTicketHolder(TicketType ticketType) {
|
||||
return new TokenHolder(new WeixinTicketCreator(this.appId, ticketType,
|
||||
this.tokenHolder), this.tokenHolder.getTokenStorager());
|
||||
return new TokenHolder(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenHolder),
|
||||
this.tokenHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,10 +230,8 @@ public class WeixinProxy {
|
||||
*
|
||||
* @param mediaId
|
||||
* 存储在微信服务器上的媒体标识
|
||||
* @param mediaType
|
||||
* 媒体类型
|
||||
* @param isMaterial
|
||||
* 是否永久素材
|
||||
* 是否下载永久素材
|
||||
* @return 写入硬盘后的文件对象
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
@@ -261,7 +241,8 @@ public class WeixinProxy {
|
||||
*/
|
||||
public File downloadMediaFile(String mediaId, boolean isMaterial)
|
||||
throws WeixinException {
|
||||
return mediaApi.downloadMediaFile(mediaId, isMaterial);
|
||||
return mediaApi.downloadMediaFile(mediaId, isMaterial,
|
||||
settings.getMediaPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1215,11 +1196,13 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 生成带参数的二维码
|
||||
*
|
||||
* @return 硬盘存储的文件对象
|
||||
* @param parameter
|
||||
* 二维码参数
|
||||
* @throws WeixinException
|
||||
* @see {@link #createQR(QRParameter)}
|
||||
*/
|
||||
public File createQRFile(QRParameter parameter) throws WeixinException {
|
||||
public File createQRFile(QRParameter parameter) throws WeixinException {
|
||||
return qrApi.createQRFile(parameter, settings.getQrcodePath());
|
||||
}
|
||||
|
||||
@@ -1463,5 +1446,5 @@ public class WeixinProxy {
|
||||
throws WeixinException {
|
||||
return dataApi.datacube(datacubeType, date);
|
||||
}
|
||||
|
||||
|
||||
public final static String VERSION = "1.6.7";
|
||||
|
||||
@@ -48,8 +48,6 @@ import com.foxinmy.weixin4j.util.IOUtil;
|
||||
import com.foxinmy.weixin4j.util.ObjectId;
|
||||
import com.foxinmy.weixin4j.util.RegexUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConst;
|
||||
import com.foxinmy.weixin4j.util.WeixinErrorUtil;
|
||||
|
||||
/**
|
||||
@@ -238,7 +236,11 @@ public class MediaApi extends MpApi {
|
||||
*
|
||||
* @param mediaId
|
||||
* 存储在微信服务器上的媒体标识
|
||||
* @return 写入硬盘后的文件对象,存储路径见weixin4j.properties配置
|
||||
* @param isMaterial
|
||||
* 是否下载永久素材
|
||||
* @param mediaPath
|
||||
* 媒体素材保存路径
|
||||
* @return 写入硬盘后的文件对象
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/11/07b6b76a6b6e8848e855a435d5e34a5f.html">下载临时媒体文件</a>
|
||||
@@ -246,12 +248,10 @@ public class MediaApi extends MpApi {
|
||||
* href="http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html">下载永久媒体素材</a>
|
||||
* @see {@link #downloadMedia(String,boolean)}
|
||||
*/
|
||||
public File downloadMediaFile(String mediaId, boolean isMaterial)
|
||||
throws WeixinException {
|
||||
String media_path = Weixin4jConfigUtil.getValue("media.path",
|
||||
Weixin4jConst.DEFAULT_MEDIA_PATH);
|
||||
public File downloadMediaFile(String mediaId, boolean isMaterial,
|
||||
String mediaPath) throws WeixinException {
|
||||
final String prefixName = String.format("%s.", mediaId);
|
||||
File[] files = new File(media_path).listFiles(new FilenameFilter() {
|
||||
File[] files = new File(mediaPath).listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.startsWith(prefixName);
|
||||
@@ -261,7 +261,7 @@ public class MediaApi extends MpApi {
|
||||
return files[0];
|
||||
}
|
||||
MediaDownloadResult result = downloadMedia(mediaId, isMaterial);
|
||||
File file = new File(media_path + File.separator + result.getFileName());
|
||||
File file = new File(mediaPath + File.separator + result.getFileName());
|
||||
OutputStream os = null;
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
|
||||
@@ -7,11 +7,12 @@ import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.mp.model.OauthToken;
|
||||
import com.foxinmy.weixin4j.mp.model.User;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* oauth授权
|
||||
@@ -25,13 +26,23 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class OauthApi extends MpApi {
|
||||
|
||||
private final WeixinAccount account;
|
||||
|
||||
public OauthApi() {
|
||||
this(Weixin4jConfigUtil.getWeixinAccount());
|
||||
}
|
||||
|
||||
public OauthApi(WeixinAccount account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link #getAuthorizeURL(String, String,String)}
|
||||
*
|
||||
* @return 请求授权的URL
|
||||
*/
|
||||
public String getAuthorizeURL() {
|
||||
String appId = DEFAULT_WEIXIN_ACCOUNT.getId();
|
||||
String appId = account.getId();
|
||||
String redirectUri = Weixin4jConfigUtil
|
||||
.getValue("user.oauth.redirect.uri");
|
||||
return getAuthorizeURL(appId, redirectUri, "state", "snsapi_base");
|
||||
@@ -67,8 +78,7 @@ public class OauthApi extends MpApi {
|
||||
* @return
|
||||
*/
|
||||
public OauthToken getOauthToken(String code) throws WeixinException {
|
||||
return getOauthToken(code, DEFAULT_WEIXIN_ACCOUNT.getId(),
|
||||
DEFAULT_WEIXIN_ACCOUNT.getSecret());
|
||||
return getOauthToken(code, account.getId(), account.getSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +110,7 @@ public class OauthApi extends MpApi {
|
||||
* @return
|
||||
*/
|
||||
public OauthToken refreshToken(String refreshToken) throws WeixinException {
|
||||
return refreshToken(DEFAULT_WEIXIN_ACCOUNT.getId(), refreshToken);
|
||||
return refreshToken(account.getId(), refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,9 @@ import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.settings.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.settings.Weixin4jPaySettings;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.type.BillType;
|
||||
@@ -51,8 +54,6 @@ import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConst;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
|
||||
/**
|
||||
@@ -66,23 +67,27 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
*/
|
||||
public class Pay2Api extends MpApi {
|
||||
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
private final Weixin4jPaySettings settings;
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
public Pay2Api() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class));
|
||||
this(new Weixin4jPaySettings());
|
||||
}
|
||||
|
||||
public Pay2Api(WeixinPayAccount weixinAccount) {
|
||||
this(weixinAccount, DEFAULT_TOKEN_STORAGER);
|
||||
public Pay2Api(Weixin4jPaySettings settings) {
|
||||
this(settings, new FileTokenStorager(
|
||||
Weixin4jSettings.DEFAULT_TOKEN_PATH));
|
||||
}
|
||||
|
||||
public Pay2Api(WeixinPayAccount weixinAccount, TokenStorager tokenStorager) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.tokenHolder = new TokenHolder(new WeixinTokenCreator(
|
||||
weixinAccount.getId(), weixinAccount.getSecret()),
|
||||
tokenStorager);
|
||||
public Pay2Api(Weixin4jPaySettings settings, TokenStorager tokenStorager) {
|
||||
this.settings = settings;
|
||||
this.tokenHolder = new TokenHolder(
|
||||
new WeixinTokenCreator(settings.getPayAccount().getId(),
|
||||
settings.getPayAccount().getSecret()), tokenStorager);
|
||||
}
|
||||
|
||||
public WeixinPayAccount getPayAccount() {
|
||||
return this.settings.getPayAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,20 +142,20 @@ public class Pay2Api extends MpApi {
|
||||
double totalFee, String notifyUrl, String createIp, String attach,
|
||||
Date timeStart, Date timeExpire, double transportFee,
|
||||
double productFee, String goodsTag) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(
|
||||
weixinAccount.getPartnerId(), body, outTradeNo, totalFee,
|
||||
notifyUrl, createIp);
|
||||
PayPackageV2 payPackage = new PayPackageV2(settings.getPayAccount()
|
||||
.getPartnerId(), body, outTradeNo, totalFee, notifyUrl,
|
||||
createIp);
|
||||
payPackage.setAttach(attach);
|
||||
payPackage.setTimeStart(timeStart);
|
||||
payPackage.setTimeExpire(timeExpire);
|
||||
payPackage.setTransportFee(transportFee);
|
||||
payPackage.setProductFee(productFee);
|
||||
payPackage.setGoodsTag(goodsTag);
|
||||
PayRequest payRequest = new PayRequest(weixinAccount.getId(),
|
||||
DigestUtil.packageSign(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
payRequest.setPaySign(DigestUtil.paysignSha(payRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
PayRequest payRequest = new PayRequest(getPayAccount().getId(),
|
||||
DigestUtil.packageSign(payPackage, getPayAccount()
|
||||
.getPartnerKey()));
|
||||
payRequest.setPaySign(DigestUtil.paysignSha(payRequest, getPayAccount()
|
||||
.getPaySignKey()));
|
||||
payRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(payRequest);
|
||||
}
|
||||
@@ -166,14 +171,14 @@ public class Pay2Api extends MpApi {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appid", getPayAccount().getId());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("productid", productId);
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("appkey", getPayAccount().getPaySignKey());
|
||||
String sign = DigestUtil.paysignSha(map, null);
|
||||
String ordernative_v2_uri = getRequestUri("ordernative_v2_uri");
|
||||
return String.format(ordernative_v2_uri, sign, weixinAccount.getId(),
|
||||
return String.format(ordernative_v2_uri, sign, getPayAccount().getId(),
|
||||
productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
@@ -193,23 +198,23 @@ public class Pay2Api extends MpApi {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(idQuery.getType().getName()).append("=")
|
||||
.append(idQuery.getId());
|
||||
sb.append("&partner=").append(weixinAccount.getPartnerId());
|
||||
sb.append("&partner=").append(getPayAccount().getPartnerId());
|
||||
String part = sb.toString();
|
||||
sb.append("&key=").append(weixinAccount.getPartnerKey());
|
||||
sb.append("&key=").append(getPayAccount().getPartnerKey());
|
||||
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
|
||||
sb.delete(0, sb.length());
|
||||
sb.append(part).append("&sign=").append(sign);
|
||||
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("appid", weixinAccount.getId());
|
||||
obj.put("appkey", weixinAccount.getPaySignKey());
|
||||
obj.put("appid", getPayAccount().getId());
|
||||
obj.put("appkey", getPayAccount().getPaySignKey());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
String signature = DigestUtil.paysignSha(obj, null);
|
||||
|
||||
obj.clear();
|
||||
obj.put("appid", weixinAccount.getId());
|
||||
obj.put("appid", getPayAccount().getId());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
obj.put("app_signature", signature);
|
||||
@@ -271,20 +276,20 @@ public class Pay2Api extends MpApi {
|
||||
// 填写为 1.0 时,操作员密码为明文
|
||||
// 填写为 1.1 时,操作员密码为 MD5(密码)值
|
||||
map.put("service_version", "1.1");
|
||||
map.put("partner", weixinAccount.getPartnerId());
|
||||
map.put("partner", getPayAccount().getPartnerId());
|
||||
map.put("out_refund_no", outRefundNo);
|
||||
map.put("total_fee", DateUtil.formaFee2Fen(totalFee));
|
||||
map.put("refund_fee", DateUtil.formaFee2Fen(refundFee));
|
||||
map.put(idQuery.getType().getName(), idQuery.getId());
|
||||
if (StringUtil.isBlank(opUserId)) {
|
||||
opUserId = weixinAccount.getPartnerId();
|
||||
opUserId = getPayAccount().getPartnerId();
|
||||
}
|
||||
map.put("op_user_id", opUserId);
|
||||
if (mopara != null && !mopara.isEmpty()) {
|
||||
map.putAll(mopara);
|
||||
}
|
||||
String sign = DigestUtil.paysignMd5(map,
|
||||
weixinAccount.getPartnerKey());
|
||||
String sign = DigestUtil.paysignMd5(map, getPayAccount()
|
||||
.getPartnerKey());
|
||||
map.put("sign", sign.toUpperCase());
|
||||
|
||||
SSLContext ctx = null;
|
||||
@@ -319,8 +324,8 @@ public class Pay2Api extends MpApi {
|
||||
KeyManagerFactory kmf = KeyManagerFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.SunX509);
|
||||
ks = KeyStore.getInstance(com.foxinmy.weixin4j.model.Consts.PKCS12);
|
||||
ks.load(ca, weixinAccount.getPartnerId().toCharArray());
|
||||
kmf.init(ks, weixinAccount.getPartnerId().toCharArray());
|
||||
ks.load(ca, getPayAccount().getPartnerId().toCharArray());
|
||||
kmf.init(ks, getPayAccount().getPartnerId().toCharArray());
|
||||
|
||||
ctx = SSLContext.getInstance(com.foxinmy.weixin4j.model.Consts.TLS);
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
|
||||
@@ -451,23 +456,22 @@ public class Pay2Api extends MpApi {
|
||||
billType = BillType.ALL;
|
||||
}
|
||||
String formatBillDate = DateUtil.fortmat2yyyyMMdd(billDate);
|
||||
String bill_path = Weixin4jConfigUtil.getValue("bill.path",
|
||||
Weixin4jConst.DEFAULT_BILL_PATH);
|
||||
String fileName = String.format("%s_%s_%s.txt", formatBillDate,
|
||||
billType.name().toLowerCase(), weixinAccount.getId());
|
||||
File file = new File(String.format("%s/%s", bill_path, fileName));
|
||||
billType.name().toLowerCase(), getPayAccount().getId());
|
||||
File file = new File(String.format("%s/%s", settings.getBillPath(),
|
||||
fileName));
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
String downloadbill_uri = getRequestUri("downloadbill_v2_uri");
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("spid", weixinAccount.getPartnerId());
|
||||
map.put("spid", getPayAccount().getPartnerId());
|
||||
map.put("trans_time", DateUtil.fortmat2yyyy_MM_dd(billDate));
|
||||
map.put("stamp", DateUtil.timestamp2string());
|
||||
map.put("cft_signtype", "0");
|
||||
map.put("mchtype", Integer.toString(billType.getVal()));
|
||||
map.put("key", weixinAccount.getPartnerKey());
|
||||
map.put("key", getPayAccount().getPartnerKey());
|
||||
String sign = DigestUtil.MD5(MapUtil.toJoinString(map, false, false));
|
||||
map.put("sign", sign.toLowerCase());
|
||||
WeixinResponse response = weixinExecutor.get(downloadbill_uri, map);
|
||||
@@ -517,9 +521,10 @@ public class Pay2Api extends MpApi {
|
||||
String refundquery_uri = getRequestUri("refundquery_v2_uri");
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("input_charset", Consts.UTF_8.name());
|
||||
map.put("partner", weixinAccount.getPartnerId());
|
||||
map.put("partner", getPayAccount().getPartnerId());
|
||||
map.put(idQuery.getType().getName(), idQuery.getId());
|
||||
String sign = DigestUtil.paysignMd5(map, weixinAccount.getPartnerKey());
|
||||
String sign = DigestUtil.paysignMd5(map, getPayAccount()
|
||||
.getPartnerKey());
|
||||
map.put("sign", sign.toLowerCase());
|
||||
WeixinResponse response = weixinExecutor.get(refundquery_uri, map);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
@@ -549,8 +554,8 @@ public class Pay2Api extends MpApi {
|
||||
Token token = tokenHolder.getToken();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("appid", getPayAccount().getId());
|
||||
map.put("appkey", getPayAccount().getPaySignKey());
|
||||
map.put("openid", openId);
|
||||
map.put("transid", transid);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
|
||||
@@ -13,8 +13,6 @@ import com.foxinmy.weixin4j.mp.model.QRParameter;
|
||||
import com.foxinmy.weixin4j.mp.model.QRResult;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.IOUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConst;
|
||||
|
||||
/**
|
||||
* 二维码相关API
|
||||
@@ -55,7 +53,8 @@ public class QrApi extends MpApi {
|
||||
QRResult result = response.getAsObject(new TypeReference<QRResult>() {
|
||||
});
|
||||
qr_uri = getRequestUri("qr_image_uri");
|
||||
response = weixinExecutor.get(String.format(qr_uri, result.getTicket()));
|
||||
response = weixinExecutor
|
||||
.get(String.format(qr_uri, result.getTicket()));
|
||||
try {
|
||||
result.setContent(IOUtil.toByteArray(response.getBody()));
|
||||
} catch (IOException e) {
|
||||
@@ -72,6 +71,8 @@ public class QrApi extends MpApi {
|
||||
*
|
||||
* @param parameter
|
||||
* 二维码参数
|
||||
* @param qrcodePath
|
||||
* 二维码保存路径
|
||||
* @return 硬盘存储的文件对象
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
@@ -79,13 +80,12 @@ public class QrApi extends MpApi {
|
||||
* @see #createQR(QRParameter)
|
||||
* @see com.foxinmy.weixin4j.mp.model.QRParameter
|
||||
*/
|
||||
public File createQRFile(QRParameter parameter) throws WeixinException {
|
||||
String qr_path = Weixin4jConfigUtil.getValue("qrcode.path",
|
||||
Weixin4jConst.DEFAULT_QRCODE_PATH);
|
||||
public File createQRFile(QRParameter parameter, String qrcodePath)
|
||||
throws WeixinException {
|
||||
String filename = String.format("%s_%s_%d.jpg", parameter.getQrType()
|
||||
.name(), parameter.getSceneValue(), parameter
|
||||
.getExpireSeconds());
|
||||
File file = new File(qr_path + File.separator + filename);
|
||||
File file = new File(qrcodePath + File.separator + filename);
|
||||
if (parameter.getQrType().ordinal() > 0 && file.exists()) {
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
# \u6d4b\u8bd5\u4e4b\u7528 \u6b63\u5f0f\u73af\u5883\u4e0bcopy\u4e00\u4efd\u5230classpath
|
||||
# \u516c\u4f17\u53f7\u4fe1\u606f
|
||||
weixin4j.account={"id":"wx4ab8f8de58159a57","secret":"1d4eb0f4bf556aaed539f30ed05ca795",\
|
||||
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"partnerId":"V2\u7248\u672c\u4e0b\u7684\u8d22\u4ed8\u901a\u7684\u5546\u6237\u53f7 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"partnerKey":"V2\u7248\u672c\u4e0b\u7684\u8d22\u4ed8\u901a\u5546\u6237\u6743\u9650\u5bc6\u94a5Key \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"paySignKey":"\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8c03\u7528API\u7684\u5bc6\u94a5 \u670d\u52a1\u53f7\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165"}
|
||||
"mchId":"V3.x\u7248\u672c\u4e0b\u7684\u5fae\u4fe1\u5546\u6237\u53f7 \u5fae\u4fe1\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"certificateKey":"\u52a0\u8f7d\u652f\u4ed8\u8bc1\u4e66\u6587\u4ef6\u7684\u5bc6\u7801 \u5982\u679c\u4e0d\u586b\u5199\u5219\u9ed8\u8ba4\u83b7\u53d6mchId\u4f5c\u4e3a\u5bc6\u7801",\
|
||||
"partnerId":"V2\u7248\u672c\u4e0b\u7684\u8d22\u4ed8\u901a\u7684\u5546\u6237\u53f7 \u8001\u7248\u672c\u5fae\u4fe1\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"partnerKey":"V2\u7248\u672c\u4e0b\u7684\u8d22\u4ed8\u901a\u5546\u6237\u6743\u9650\u5bc6\u94a5Key \u8001\u7248\u672c\u5fae\u4fe1\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165",\
|
||||
"paySignKey":"\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8c03\u7528API\u7684\u5bc6\u94a5 \u5fae\u4fe1\u652f\u4ed8\u65f6\u9700\u8981\u586b\u5165"}
|
||||
|
||||
# \u4f7f\u7528FileTokenStorager\u65f6token\u7684\u5b58\u653e\u8def\u5f84
|
||||
# \u4f7f\u7528FileTokenStorager\u65f6token\u7684\u5b58\u653e\u8def\u5f84(\u5982\u679c\u4e0d\u586b\u5219\u9ed8\u8ba4\u4e3aWeixin4jConst#DEFAULT_TOKEN_PATH)
|
||||
weixin4j.token.path=/tmp/weixin4j/token
|
||||
# \u4e8c\u7ef4\u7801\u4fdd\u5b58\u8def\u5f84
|
||||
# \u4e8c\u7ef4\u7801\u4fdd\u5b58\u8def\u5f84(\u5982\u679c\u4e0d\u586b\u5219\u9ed8\u8ba4\u4e3aWeixin4jConst#DEFAULT_TOKEN_PATH)
|
||||
weixin4j.qrcode.path=/tmp/weixin4j/qrcode
|
||||
# \u5a92\u4f53\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84
|
||||
# \u5a92\u4f53\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84(\u5982\u679c\u4e0d\u586b\u5219\u9ed8\u8ba4\u4e3aWeixin4jConst#DEFAULT_MEDIA_PATH)
|
||||
weixin4j.media.path=/tmp/weixin4j/media
|
||||
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84
|
||||
# \u5bf9\u8d26\u5355\u4fdd\u5b58\u8def\u5f84(\u5982\u679c\u4e0d\u586b\u5219\u9ed8\u8ba4\u4e3aWeixin4jConst#DEFAULT_BILL_PATH)
|
||||
weixin4j.bill.path=/tmp/weixin4j/bill
|
||||
# ca\u8bc1\u4e66\u5b58\u653e\u7684\u5b8c\u6574\u8def\u5f84 (V2\u7248\u672c\u540e\u7f00\u4e3a*.pfx,V3\u7248\u672c\u540e\u7f00\u4e3a*.p12)
|
||||
weixin4j.certificate.file=/tmp/weixin4j/xxxxx.p12
|
||||
# classpath\u8def\u5f84\u4e0b\u53ef\u4ee5\u8fd9\u4e48\u5199
|
||||
# classpath\u8def\u5f84\u4e0b\u53ef\u4ee5\u8fd9\u4e48\u5199(\u5982\u679c\u4e0d\u586b\u5219\u9ed8\u8ba4\u4e3aWeixin4jConst#DEFAULT_CAFILE_PATH)
|
||||
# weixin4j.certificate.file=classpath:xxxxx.pfx
|
||||
|
||||
# \u7528\u6237oauth\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
||||
# \u7528\u6237oauth\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url(\u5728\u4f7f\u7528OauthApi\u65f6\u586b\u5199)
|
||||
weixin4j.user.oauth.redirect.uri=
|
||||
Reference in New Issue
Block a user