主要新增了企业号的第三方应用API
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package com.foxinmy.weixin4j.api;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
|
||||
/**
|
||||
* API基础
|
||||
@@ -17,9 +18,10 @@ import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php">微信企业号API文档</a>
|
||||
*/
|
||||
public abstract class BaseApi {
|
||||
|
||||
protected final WeixinHttpClient weixinClient = new WeixinHttpClient();
|
||||
|
||||
protected abstract ResourceBundle getWeixinBundle();
|
||||
protected abstract String getConfigValue(String key);
|
||||
|
||||
protected String getRequestUri(String key) {
|
||||
String url = getConfigValue(key);
|
||||
@@ -36,7 +38,8 @@ public abstract class BaseApi {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected String getConfigValue(String key) {
|
||||
return getWeixinBundle().getString(key);
|
||||
}
|
||||
/**
|
||||
* 默认token使用File的方式存储
|
||||
*/
|
||||
public final static TokenStorager DEFAULT_TOKEN_STORAGER = new FileTokenStorager();
|
||||
}
|
||||
|
||||
@@ -486,10 +486,14 @@
|
||||
<code>43011</code>
|
||||
<text>需要企业授权</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>43013</code>
|
||||
<text>应用对成员不可见</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>44001</code>
|
||||
<desc>empty media data</desc>
|
||||
<text>空白的二进制数据</text>
|
||||
<text>多媒体文件为空</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>44002</code>
|
||||
@@ -859,7 +863,7 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>60125</code>
|
||||
<text>部门名字长度超过限制</text>
|
||||
<text>非法部门名字,长度超过限制、重名等</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>60126</code>
|
||||
|
||||
@@ -27,41 +27,4 @@ public final class Consts {
|
||||
public static final String SHA1 = "SHA-1";
|
||||
public static final String PROTOCOL_FILE = "file";
|
||||
public static final String PROTOCOL_JAR = "jar";
|
||||
|
||||
/**
|
||||
* 公众平台获取token的url
|
||||
*/
|
||||
public static final String MP_ASSESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
|
||||
/**
|
||||
* 企业号获取token的url
|
||||
*/
|
||||
public static final String QY_ASSESS_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
|
||||
/**
|
||||
* 企业号提供商获取token的url
|
||||
*/
|
||||
public static final String QY_PROVIDER_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
||||
/**
|
||||
* 公众平台jssdk获取token的url
|
||||
*/
|
||||
public static final String MP_JS_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
|
||||
/**
|
||||
* 企业号jssdk获取token的url
|
||||
*/
|
||||
public static final String QY_JS_TICKET_URL = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s";
|
||||
/**
|
||||
* 商户平台下统一订单生成的url
|
||||
*/
|
||||
public static final String UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||
/**
|
||||
* 商户平台下刷卡支付的url
|
||||
*/
|
||||
public static final String MICROPAYURL = "https://api.mch.weixin.qq.com/pay/micropay";
|
||||
/**
|
||||
* V2支付下natvie支付的url
|
||||
*/
|
||||
public static final String NATIVEURLV2 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&noncestr=%s";
|
||||
/**
|
||||
* 商户平台(V3)下native支付的url
|
||||
*/
|
||||
public static final String NATIVEURLV3 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Token implements Serializable {
|
||||
@JSONField(name = "expires_in")
|
||||
private int expiresIn;
|
||||
/**
|
||||
* token创建的时间 只在FileTokenHolder模式下有效
|
||||
* token创建的时间 只在FileTokenStorager模式下有效
|
||||
*/
|
||||
private long time;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class FileTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cachingToken(Token token, String cacheKey)
|
||||
public void cachingToken(String cacheKey, Token token)
|
||||
throws WeixinException {
|
||||
try {
|
||||
XmlStream.toXML(
|
||||
|
||||
@@ -15,21 +15,50 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
*/
|
||||
public final class TokenHolder {
|
||||
|
||||
/**
|
||||
* token的创建
|
||||
*/
|
||||
private final TokenCreator tokenCreator;
|
||||
/**
|
||||
* token的存储
|
||||
*/
|
||||
private final TokenStorager tokenStorager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tokenCreator
|
||||
* token创建器
|
||||
* @param tokenStorager
|
||||
* token保存器
|
||||
*/
|
||||
public TokenHolder(TokenCreator tokenCreator, TokenStorager tokenStorager) {
|
||||
this.tokenCreator = tokenCreator;
|
||||
this.tokenStorager = tokenStorager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token对象
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public Token getToken() throws WeixinException {
|
||||
String cacheKey = tokenCreator.getCacheKey();
|
||||
Token token = tokenStorager.lookupToken(cacheKey);
|
||||
if (token == null) {
|
||||
token = tokenCreator.createToken();
|
||||
tokenStorager.cachingToken(token, cacheKey);
|
||||
tokenStorager.cachingToken(cacheKey, token);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token字符串
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getAccessToken() throws WeixinException {
|
||||
return getToken().getAccessToken();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,13 @@ public interface TokenStorager {
|
||||
/**
|
||||
* 缓存新的token
|
||||
*
|
||||
* @param token
|
||||
* 新产生的token
|
||||
* @param cacheKey
|
||||
* 缓存的名称
|
||||
*
|
||||
* @param token
|
||||
* 新产生的token
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cachingToken(Token token, String cacheKey)
|
||||
public void cachingToken(String cacheKey, Token token)
|
||||
throws WeixinException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user