🎨 优化部分代码

This commit is contained in:
Binary Wang
2020-09-20 00:21:08 +08:00
parent 7261f23689
commit e00320dd1c
12 changed files with 200 additions and 228 deletions

View File

@@ -27,13 +27,16 @@ public interface WxCpTpService {
* @param timestamp 时间戳
* @param nonce 随机数
* @param data 微信传输过来的数据有可能是echoStr有可能是xml消息
* @return the boolean
*/
boolean checkSignature(String msgSignature, String timestamp, String nonce, String data);
/**
* 获取suite_access_token, 不强制刷新suite_access_token
*
* @see #getSuiteAccessToken(boolean)
* @return the suite access token
* @throws WxErrorException the wx error exception
* @see #getSuiteAccessToken(boolean) #getSuiteAccessToken(boolean)
*/
String getSuiteAccessToken() throws WxErrorException;
@@ -47,13 +50,17 @@ public interface WxCpTpService {
* </pre>
*
* @param forceRefresh 强制刷新
* @return the suite access token
* @throws WxErrorException the wx error exception
*/
String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException;
/**
* 获得suite_ticket,不强制刷新suite_ticket
*
* @see #getSuiteTicket(boolean)
* @return the suite ticket
* @throws WxErrorException the wx error exception
* @see #getSuiteTicket(boolean) #getSuiteTicket(boolean)
*/
String getSuiteTicket() throws WxErrorException;
@@ -66,6 +73,8 @@ public interface WxCpTpService {
* </pre>
*
* @param forceRefresh 强制刷新
* @return the suite ticket
* @throws WxErrorException the wx error exception
*/
String getSuiteTicket(boolean forceRefresh) throws WxErrorException;
@@ -73,6 +82,8 @@ public interface WxCpTpService {
* 小程序登录凭证校验
*
* @param jsCode 登录时获取的 code
* @return the wx cp ma js code 2 session result
* @throws WxErrorException the wx error exception
*/
WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException;
@@ -81,6 +92,8 @@ public interface WxCpTpService {
*
* @param authCorpid 授权方corpid
* @param permanentCode 永久授权码通过get_permanent_code获取
* @return the corp token
* @throws WxErrorException the wx error exception
*/
WxAccessToken getCorpToken(String authCorpid, String permanentCode) throws WxErrorException;
@@ -88,7 +101,8 @@ public interface WxCpTpService {
* 获取企业永久授权码 .
*
* @param authCode .
* @return .
* @return . permanent code
* @throws WxErrorException the wx error exception
*/
@Deprecated
WxCpTpCorp getPermanentCode(String authCode) throws WxErrorException;
@@ -99,13 +113,11 @@ public interface WxCpTpService {
* 原来的方法实现不全
* </pre>
*
* @param authCode
* @return
*
* @param authCode the auth code
* @return permanent code info
* @throws WxErrorException the wx error exception
* @author yuan
* @since 2020-03-18
*
* @throws WxErrorException
* @since 2020 -03-18
*/
WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException;
@@ -113,28 +125,31 @@ public interface WxCpTpService {
* <pre>
* 获取预授权链接
* </pre>
*
* @param redirectUri 授权完成后的回调网址
* @param state a-zA-Z0-9的参数值不超过128个字节用于第三方自行校验session防止跨域攻击
* @return
* @throws WxErrorException
* @param state a-zA-Z0-9的参数值不超过128个字节用于第三方自行校验session防止跨域攻击
* @return pre auth url
* @throws WxErrorException the wx error exception
*/
String getPreAuthUrl(String redirectUri,String state) throws WxErrorException;
String getPreAuthUrl(String redirectUri, String state) throws WxErrorException;
/**
* 获取企业的授权信息
*
* @param authCorpId 授权企业的corpId
* @param authCorpId 授权企业的corpId
* @param permanentCode 授权企业的永久授权码
* @return
* @throws WxErrorException
* @return auth info
* @throws WxErrorException the wx error exception
*/
WxCpTpAuthInfo getAuthInfo(String authCorpId,String permanentCode) throws WxErrorException;
WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求.
*
* @param url 接口地址
* @param queryParam 请求参数
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String url, String queryParam) throws WxErrorException;
@@ -143,6 +158,8 @@ public interface WxCpTpService {
*
* @param url 接口地址
* @param postData 请求body字符串
* @return the string
* @throws WxErrorException the wx error exception
*/
String post(String url, String postData) throws WxErrorException;
@@ -153,11 +170,13 @@ public interface WxCpTpService {
* 可以参考,{@link MediaUploadRequestExecutor}的实现方法
* </pre>
*
* @param <T> 请求值类型
* @param <E> 返回值类型
* @param executor 执行器
* @param uri 请求地址
* @param data 参数
* @param <T> 请求值类型
* @param <E> 返回值类型
* @return the t
* @throws WxErrorException the wx error exception
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
@@ -189,7 +208,7 @@ public interface WxCpTpService {
/**
* 获取WxMpConfigStorage 对象.
*
* @return WxMpConfigStorage
* @return WxMpConfigStorage wx cp tp config storage
*/
WxCpTpConfigStorage getWxCpTpConfigStorage();
@@ -202,6 +221,8 @@ public interface WxCpTpService {
/**
* http请求对象.
*
* @return the request http
*/
RequestHttp<?, ?> getRequestHttp();

View File

@@ -4,8 +4,8 @@ import com.google.common.base.Joiner;
import com.google.gson.JsonObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
@@ -127,7 +127,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
}
@Override
public WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException{
public WxCpTpPermanentCodeInfo getPermanentCodeInfo(String authCode) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("auth_code", authCode);
String result = post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
@@ -136,18 +136,19 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
@Override
@SneakyThrows
public String getPreAuthUrl(String redirectUri,String state) throws WxErrorException{
String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE),null);
WxCpTpPreauthCode preauthCode = WxCpTpPreauthCode.fromJson(result);
String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id="+configStorage.getSuiteId()+
"&pre_auth_code="+preauthCode.getPreAuthCode()+"&redirect_uri="+ URLEncoder.encode(redirectUri,"utf-8");
if(StringUtils.isNotBlank(state))
preAuthUrl += "&state="+state;
public String getPreAuthUrl(String redirectUri, String state) throws WxErrorException {
String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE), null);
WxCpTpPreauthCode preAuthCode = WxCpTpPreauthCode.fromJson(result);
String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=" + configStorage.getSuiteId() +
"&pre_auth_code=" + preAuthCode.getPreAuthCode() + "&redirect_uri=" + URLEncoder.encode(redirectUri, "utf-8");
if (StringUtils.isNotBlank(state)) {
preAuthUrl += "&state=" + state;
}
return preAuthUrl;
}
@Override
public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException{
public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("auth_corpid", authCorpId);
jsonObject.addProperty("permanent_code", permanentCode);