mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 04:53:50 +08:00
issue #39 添加oauth2的支持
This commit is contained in:
@@ -128,4 +128,12 @@ public class WxConsts {
|
||||
/** 弹出地理位置选择器 */
|
||||
public static final String LOCATION_SELECT = "location_select";
|
||||
|
||||
///////////////////////
|
||||
// oauth2网页授权的scope
|
||||
///////////////////////
|
||||
/** 不弹出授权页面,直接跳转,只能获取用户openid */
|
||||
public static final String OAUTH2_SCOPE_BASE = "snsapi_base";
|
||||
/** 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息 */
|
||||
public static final String OAUTH2_SCOPE_USER_INFO = "snsapi_userinfo";
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.common.util.http;
|
||||
|
||||
import me.chanjar.weixin.common.util.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class URIUtil {
|
||||
|
||||
private static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";
|
||||
|
||||
public static String encodeURIComponent(String input) {
|
||||
if (StringUtils.isEmpty(input)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
int l = input.length();
|
||||
StringBuilder o = new StringBuilder(l * 3);
|
||||
try {
|
||||
for (int i = 0; i < l; i++) {
|
||||
String e = input.substring(i, i + 1);
|
||||
if (ALLOWED_CHARS.indexOf(e) == -1) {
|
||||
byte[] b = e.getBytes("utf-8");
|
||||
o.append(getHex(b));
|
||||
continue;
|
||||
}
|
||||
o.append(e);
|
||||
}
|
||||
return o.toString();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
private static String getHex(byte buf[]) {
|
||||
StringBuilder o = new StringBuilder(buf.length * 3);
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
int n = (int) buf[i] & 0xff;
|
||||
o.append("%");
|
||||
if (n < 0x10) {
|
||||
o.append("0");
|
||||
}
|
||||
o.append(Long.toString(n, 16).toUpperCase());
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user