1. 程式人生 > >微信企業號OAuth2.0驗證介面的呼叫步驟

微信企業號OAuth2.0驗證介面的呼叫步驟

public abstract class WechatAuthController {


public static final String CORP_ID = PropertyManager.getString(
"config.properties", "CORP_ID");


public static final String CORP_SECRET = PropertyManager.getString(
"config.properties", "CORP_SECRET");


public static final String REDIRECT_URL = PropertyManager.getString(
"config.properties", "REDIRECT_URL");


public static final String AUTHORIZE_URL = PropertyManager.getString(
"config.properties", "AUTHORIZE_URL");


public static final String QY_ACCESS_TOKEN_URL = PropertyManager.getString(
"config.properties", "QY_ACCESS_TOKEN_URL");


public static final String USER_INFO_URL = PropertyManager.getString(
"config.properties", "USER_INFO_URL");


public static String no;


public static String tel;
@RequestMapping(value = "/anon/doBusiness")
public String doBusiness(Model model, @RequestParam String code)
throws IOException {
if (StringUtils.isNullOrEmpty(code)) {
String authRedirectUrl = String.format(AUTHORIZE_URL, CORP_ID,
URLEncoder.encode(REDIRECT_URL, "UTF-8"));
return "redirect:" + authRedirectUrl;
} else {
String accessTokenUrl = String.format(QY_ACCESS_TOKEN_URL, CORP_ID,
CORP_SECRET);
String accessTokenStr = HttpConnectionUtils.doGet(accessTokenUrl);
JSONObject accessTokenObj = JSON.parseObject(accessTokenStr);
String accessToken = accessTokenObj.getString("access_token");
String userInfoUrl = String.format(USER_INFO_URL, accessToken,
code);
String userInfoStr = HttpConnectionUtils.doGet(userInfoUrl);
JSONObject userInfoObj = JSONObject.parseObject(userInfoStr);
String userid = userInfoObj.getString("UserId");
//String deviceid = userInfoObj.getString("DeviceId");


model.addAttribute("userid", userid);
//model.addAttribute("tel", deviceid);
   System.out.println(userid);
no=userid;
//tel=deviceid;
return doBusinessDetail(model, code);

}
}


public abstract String doBusinessDetail(Model model,
@RequestParam String code) throws IOException;


}