Skip to content

Commit

Permalink
🆕 binarywang#2345【企业微信】增加创建调用wx.agentConfig时所需要的签名方法
Browse files Browse the repository at this point in the history
  • Loading branch information
arbing authored and aieyes committed Jan 17, 2022
1 parent 4976ad0 commit 591bf86
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
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;
}

0 comments on commit 591bf86

Please sign in to comment.