mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-17 13:49:26 +08:00
Merge branch 'master' into develop
This commit is contained in:
@@ -152,6 +152,20 @@ public interface WxMpService {
|
||||
*/
|
||||
WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 构造第三方使用网站应用授权登录的url
|
||||
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN">网站应用微信登录开发指南</a>
|
||||
* URL格式为:https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
|
||||
* </pre>
|
||||
*
|
||||
* @param redirectURI 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
|
||||
* @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔,网页应用目前仅填写snsapi_login即可
|
||||
* @param state 非必填,用于保持请求和回调的状态,授权请求后原样带回给第三方。该参数可用于防止csrf攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加session进行校验
|
||||
* @return url
|
||||
*/
|
||||
String buildQrConnectUrl(String redirectURI, String scope, String state);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 构造oauth2授权的url连接
|
||||
|
||||
@@ -275,6 +275,23 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildQrConnectUrl(String redirectURI, String scope,
|
||||
String state) {
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append("https://open.weixin.qq.com/connect/qrconnect?");
|
||||
url.append("appid=").append(this.wxMpConfigStorage.getAppId());
|
||||
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
|
||||
url.append("&response_type=code");
|
||||
url.append("&scope=").append(scope);
|
||||
if (state != null) {
|
||||
url.append("&state=").append(state);
|
||||
}
|
||||
|
||||
url.append("#wechat_redirect");
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxErrorException {
|
||||
try {
|
||||
RequestExecutor<String, String> executor = new SimpleGetRequestExecutor();
|
||||
|
||||
Reference in New Issue
Block a user