|
@ -72,19 +72,16 @@ public class WeixinBaseController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过code获取判断openid
|
|
|
*
|
|
|
* @param code
|
|
|
* 通过openid获取Unionid
|
|
|
* @return
|
|
|
*/
|
|
|
public String getUnionIDByCode(String code) {
|
|
|
public String getUnionidByOpenid(String openid) {
|
|
|
try {
|
|
|
String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
|
|
|
String params = "appid=" + appId + "&secret=" +appSecret+ "&code=" + code + "&grant_type=authorization_code";
|
|
|
String token_url = "https://api.weixin.qq.com/cgi-bin/user/info";
|
|
|
String params = "access_token=" + getAccessToken() + "&openid=" +openid+ "&lang=zh_CN";
|
|
|
String result = HttpUtil.sendGet(token_url, params);
|
|
|
System.out.println("getOpenidByCode:"+result);
|
|
|
System.out.println("getUnionidByOpenid:"+result);
|
|
|
JSONObject json = new JSONObject(result);
|
|
|
System.out.println("result:"+json.toString());
|
|
|
if (json.has("unionid")) {
|
|
|
return json.get("unionid").toString();
|
|
|
} else {
|