mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-02 21:26:01 +08:00
🆕 #2345【企业微信】增加创建调用wx.agentConfig时所需要的签名方法
This commit is contained in:
@ -8,6 +8,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
|||||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpAgentJsapiSignature;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
||||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||||
@ -124,6 +125,18 @@ public interface WxCpService extends WxService {
|
|||||||
*/
|
*/
|
||||||
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
|
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 创建调用wx.agentConfig时所需要的签名
|
||||||
|
*
|
||||||
|
* 详情请见:https://open.work.weixin.qq.com/api/doc/90000/90136/94313
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param url url
|
||||||
|
* @return the agent jsapi signature
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
WxCpAgentJsapiSignature createAgentJsapiSignature(String url) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序登录凭证校验
|
* 小程序登录凭证校验
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import me.chanjar.weixin.common.util.crypto.SHA1;
|
|||||||
import me.chanjar.weixin.common.util.http.*;
|
import me.chanjar.weixin.common.util.http.*;
|
||||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
import me.chanjar.weixin.common.util.json.GsonParser;
|
||||||
import me.chanjar.weixin.cp.api.*;
|
import me.chanjar.weixin.cp.api.*;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpAgentJsapiSignature;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
||||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||||
@ -171,6 +172,30 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
|||||||
return jsapiSignature;
|
return jsapiSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpAgentJsapiSignature createAgentJsapiSignature(String url) throws WxErrorException {
|
||||||
|
long timestamp = System.currentTimeMillis() / 1000;
|
||||||
|
String noncestr = RandomUtils.getRandomStr();
|
||||||
|
String jsapiTicket = getAgentJsapiTicket(false);
|
||||||
|
String signature = SHA1.genWithAmple(
|
||||||
|
"jsapi_ticket=" + jsapiTicket,
|
||||||
|
"noncestr=" + noncestr,
|
||||||
|
"timestamp=" + timestamp,
|
||||||
|
"url=" + url
|
||||||
|
);
|
||||||
|
|
||||||
|
WxCpAgentJsapiSignature jsapiSignature = new WxCpAgentJsapiSignature();
|
||||||
|
jsapiSignature.setTimestamp(timestamp);
|
||||||
|
jsapiSignature.setNonceStr(noncestr);
|
||||||
|
jsapiSignature.setUrl(url);
|
||||||
|
jsapiSignature.setSignature(signature);
|
||||||
|
|
||||||
|
jsapiSignature.setCorpid(this.configStorage.getCorpId());
|
||||||
|
jsapiSignature.setAgentid(this.configStorage.getAgentId());
|
||||||
|
|
||||||
|
return jsapiSignature;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
|
public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
|
||||||
Map<String, String> params = new HashMap<>(2);
|
Map<String, String> params = new HashMap<>(2);
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用wx.agentConfig时所需要的签名信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WxCpAgentJsapiSignature implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2650119900835832545L;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String corpid;
|
||||||
|
|
||||||
|
private Integer agentid;
|
||||||
|
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
|
private String nonceStr;
|
||||||
|
|
||||||
|
private String signature;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user