Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕【企业微信】增加创建调用wx.agentConfig时所需要的签名方法 #2345

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
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.WxCpProviderToken;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
Expand Down Expand Up @@ -124,6 +125,18 @@ public interface WxCpService extends WxService {
*/
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;

/**
* 小程序登录凭证校验
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.json.GsonParser;
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.WxCpProviderToken;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
Expand Down Expand Up @@ -171,6 +172,30 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
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
public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException {
Map<String, String> params = new HashMap<>(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}