* 2015-12-04
+ weixin4j-base:【重要】修改PayUtil中的createPayJsRequest方法的返回值为MchPayRequest,便于二次发起支付。 + weixin4j-base:【重要】添加MchPayRequest的构造函数,便于二次发起支付。 + weixin4j-qy:【重要】第三方应用授权时获取永久授权码覆盖问题。
This commit is contained in:
@@ -37,10 +37,6 @@ public class SuiteApi extends QyApi {
|
||||
* 应用套件ticket
|
||||
*/
|
||||
private final SuiteTicketHolder suiteTicketHolder;
|
||||
/**
|
||||
* 应用套件永久授权码
|
||||
*/
|
||||
private final SuitePerCodeHolder suitePerCodeHolder;
|
||||
/**
|
||||
* 应用套件pre_code
|
||||
*/
|
||||
@@ -62,9 +58,6 @@ public class SuiteApi extends QyApi {
|
||||
new WeixinSuitePreCodeCreator(suiteTokenHolder,
|
||||
suiteTicketHolder.getSuiteId()),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
this.suitePerCodeHolder = new SuitePerCodeHolder(
|
||||
suiteTicketHolder.getSuiteId(),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +88,16 @@ public class SuiteApi extends QyApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用套件永久授权码
|
||||
* 应用套件永久授权码:企业号的永久授权码
|
||||
*
|
||||
* @param authCorpid
|
||||
* 授权方corpid
|
||||
* @return
|
||||
*/
|
||||
public SuitePerCodeHolder getPerCodeHolder() {
|
||||
return this.suitePerCodeHolder;
|
||||
public SuitePerCodeHolder getPerCodeHolder(String authCorpId) {
|
||||
return new SuitePerCodeHolder(authCorpId,
|
||||
suiteTicketHolder.getSuiteId(),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,9 +107,9 @@ public class SuiteApi extends QyApi {
|
||||
* 授权方corpid
|
||||
* @return 企业号token
|
||||
*/
|
||||
public TokenHolder createTokenHolder(String authCorpid) {
|
||||
return new TokenHolder(new WeixinTokenSuiteCreator(authCorpid,
|
||||
suitePerCodeHolder, suiteTokenHolder),
|
||||
public TokenHolder createTokenHolder(String authCorpId) {
|
||||
return new TokenHolder(new WeixinTokenSuiteCreator(authCorpId,
|
||||
getPerCodeHolder(authCorpId), suiteTokenHolder),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
@@ -165,6 +162,9 @@ public class SuiteApi extends QyApi {
|
||||
obj.put("corp_info", obj.remove("auth_corp_info"));
|
||||
obj.put("user_info", obj.remove("auth_user_info"));
|
||||
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
||||
// 微信授权企业号的永久授权码
|
||||
SuitePerCodeHolder suitePerCodeHolder = getPerCodeHolder(oInfo
|
||||
.getCorpInfo().getCorpId());
|
||||
// 缓存微信企业号access_token
|
||||
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(null,
|
||||
suitePerCodeHolder, suiteTokenHolder);
|
||||
@@ -182,7 +182,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 获取企业号的授权信息
|
||||
*
|
||||
* @param authCorpid
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @return 授权方信息
|
||||
* @throws WeixinException
|
||||
@@ -190,12 +190,13 @@ public class SuiteApi extends QyApi {
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E7.9A.84.E6.8E.88.E6.9D.83.E4.BF.A1.E6.81.AF">获取企业号的授权信息</a>
|
||||
*/
|
||||
public OUserInfo getOAuthInfo(String authCorpid) throws WeixinException {
|
||||
public OUserInfo getOAuthInfo(String authCorpId) throws WeixinException {
|
||||
String suite_get_authinfo_uri = getRequestUri("suite_get_authinfo_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpid);
|
||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
.getPermanentCode());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_get_authinfo_uri,
|
||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||
@@ -208,7 +209,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 获取企业号应用
|
||||
*
|
||||
* @param authCorpid
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @param agentid
|
||||
* 授权方应用id
|
||||
@@ -218,13 +219,14 @@ public class SuiteApi extends QyApi {
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E5.BA.94.E7.94.A8">获取企业号应用</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public AgentInfo getAgent(String authCorpid, int agentid)
|
||||
public AgentInfo getAgent(String authCorpId, int agentid)
|
||||
throws WeixinException {
|
||||
String suite_get_agent_uri = getRequestUri("suite_get_agent_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpid);
|
||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
.getPermanentCode());
|
||||
obj.put("agentid", agentid);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_get_agent_uri,
|
||||
@@ -245,7 +247,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 设置企业应用的选项设置信息,如:地理位置上报等
|
||||
*
|
||||
* @param authCorpid
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @param agentSet
|
||||
* 设置信息
|
||||
@@ -255,13 +257,14 @@ public class SuiteApi extends QyApi {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult setAgent(String authCorpid, AgentSetter agentSet)
|
||||
public JsonResult setAgent(String authCorpId, AgentSetter agentSet)
|
||||
throws WeixinException {
|
||||
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpid);
|
||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
.getPermanentCode());
|
||||
obj.put("agent", agentSet);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_set_agent_uri,
|
||||
|
||||
@@ -15,10 +15,13 @@ import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
*/
|
||||
public class SuitePerCodeHolder {
|
||||
|
||||
private final String authCorpId;
|
||||
private final String suiteId;
|
||||
private final TokenStorager tokenStorager;
|
||||
|
||||
public SuitePerCodeHolder(String suiteId, TokenStorager tokenStorager) {
|
||||
public SuitePerCodeHolder(String authCorpId, String suiteId,
|
||||
TokenStorager tokenStorager) {
|
||||
this.authCorpId = authCorpId;
|
||||
this.suiteId = suiteId;
|
||||
this.tokenStorager = tokenStorager;
|
||||
}
|
||||
@@ -42,11 +45,11 @@ public class SuitePerCodeHolder {
|
||||
* @return
|
||||
*/
|
||||
public String getCacheKey() {
|
||||
return String.format("qy_suite_percode_%s", suiteId);
|
||||
return String.format("qy_suite_percode_%s:%s", suiteId, authCorpId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找永久二维码
|
||||
* 查找永久授权码
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
@@ -58,4 +61,8 @@ public class SuitePerCodeHolder {
|
||||
public String getSuiteId() {
|
||||
return this.suiteId;
|
||||
}
|
||||
|
||||
public String getAuthCorpId() {
|
||||
return this.authCorpId;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -23,22 +23,22 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
public class WeixinTokenSuiteCreator implements TokenCreator {
|
||||
|
||||
private final WeixinRequestExecutor weixinExecutor;
|
||||
private final String authCorpid;
|
||||
private final String authCorpId;
|
||||
private final SuitePerCodeHolder perCodeHolder;
|
||||
private final TokenHolder suiteTokenHolder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteSecret
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @param perCodeHolder
|
||||
* 永久授权码
|
||||
* @param suiteTokenHolder
|
||||
* 套件token
|
||||
*/
|
||||
public WeixinTokenSuiteCreator(String authCorpid,
|
||||
public WeixinTokenSuiteCreator(String authCorpId,
|
||||
SuitePerCodeHolder perCodeHolder, TokenHolder suiteTokenHolder) {
|
||||
this.authCorpid = authCorpid;
|
||||
this.authCorpId = authCorpId;
|
||||
this.perCodeHolder = perCodeHolder;
|
||||
this.suiteTokenHolder = suiteTokenHolder;
|
||||
this.weixinExecutor = new WeixinRequestExecutor();
|
||||
@@ -46,14 +46,15 @@ public class WeixinTokenSuiteCreator implements TokenCreator {
|
||||
|
||||
@Override
|
||||
public String getCacheKey() {
|
||||
return String.format("qy_token_suite_%s", perCodeHolder.getSuiteId());
|
||||
return String.format("qy_token_suite_%s:%s",
|
||||
perCodeHolder.getSuiteId(), authCorpId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token createToken() throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", perCodeHolder.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpid);
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", perCodeHolder.getPermanentCode());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(URLConsts.TOKEN_SUITE_URL,
|
||||
|
||||
Reference in New Issue
Block a user