|
@ -19,22 +19,17 @@ public class WechatInfoService {
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public String getOpenidByCode(String code,String appId,String appSecret) {
|
|
|
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 result = HttpUtil.sendGet(token_url, params);
|
|
|
System.out.println("getOpenidByCode:"+result);
|
|
|
JSONObject json = new JSONObject(result);
|
|
|
if (json.has("openid")) {
|
|
|
return json.get("openid").toString();
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
public String getOpenidByCode(String code,String appId,String appSecret) throws Exception {
|
|
|
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 result = HttpUtil.sendGet(token_url, params);
|
|
|
System.out.println("getOpenidByCode:"+result);
|
|
|
JSONObject json = new JSONObject(result);
|
|
|
if (json.has("openid")) {
|
|
|
return json.get("openid").toString();
|
|
|
}else{
|
|
|
throw new Exception(result);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -43,7 +38,7 @@ public class WechatInfoService {
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public String getOpenidByCode(String code,String wxId) {
|
|
|
public String getOpenidByCode(String code,String wxId) throws Exception {
|
|
|
//通过wxId获取appId和appSecret
|
|
|
WxWechatDO wxWechatDO = wechatDao.findById(wxId);
|
|
|
return getOpenidByCode(code,wxWechatDO.getAppId(),wxWechatDO.getAppSecret());
|