|
@ -13,6 +13,7 @@ import java.util.Map;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
|
import com.yihu.wlyy.util.*;
|
|
import com.yihu.wlyy.util.*;
|
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -53,17 +54,22 @@ public class WeixinBaseController extends BaseController {
|
|
* @param code
|
|
* @param code
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public String getOpenidByCode(String code) {
|
|
|
|
|
|
public Map<String,Object> getOpenidByCode(String code) {
|
|
try {
|
|
try {
|
|
String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
|
|
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 params = "appid=" + appId + "&secret=" +appSecret+ "&code=" + code + "&grant_type=authorization_code";
|
|
String result = HttpUtil.sendGet(token_url, params);
|
|
String result = HttpUtil.sendGet(token_url, params);
|
|
System.out.println("getOpenidByCode:"+result);
|
|
System.out.println("getOpenidByCode:"+result);
|
|
JSONObject json = new JSONObject(result);
|
|
JSONObject json = new JSONObject(result);
|
|
|
|
Map<String,Object> map = new HashedMap();
|
|
if (json.has("openid")) {
|
|
if (json.has("openid")) {
|
|
return json.get("openid").toString();
|
|
|
|
|
|
map.put("openid",json.get("openid").toString());
|
|
|
|
if(json.has("unionid")){
|
|
|
|
map.put("unionid",json.get("unionid").toString());
|
|
|
|
}
|
|
|
|
return map;
|
|
} else {
|
|
} else {
|
|
return null;
|
|
|
|
|
|
return map;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
error(e);
|
|
error(e);
|