use of build.dream.catering.models.miniprogram.ObtainSessionWithJsCodeModel in project erp-catering by liuyandong33.
the class MiniProgramController method obtainSessionWithJsCode.
@RequestMapping(value = "/obtainSessionWithJsCode")
@ResponseBody
public String obtainSessionWithJsCode() {
ApiRest apiRest = null;
Map<String, String> requestParameters = ApplicationHandler.getRequestParameters();
try {
ObtainSessionWithJsCodeModel obtainSessionWithJsCodeModel = ApplicationHandler.instantiateObject(ObtainSessionWithJsCodeModel.class, requestParameters);
obtainSessionWithJsCodeModel.validateAndThrow();
Map<String, String> obtainSessionRequestParameters = new HashMap<String, String>();
obtainSessionRequestParameters.put("appid", "wxc375e036b110a28f");
obtainSessionRequestParameters.put("secret", "415627f3ec7bf51497a98e94546affa7");
obtainSessionRequestParameters.put("js_code", obtainSessionWithJsCodeModel.getCode());
obtainSessionRequestParameters.put("grant_type", "authorization_code");
String obtainSessionResult = WebUtils.doGetWithRequestParameters("https://api.weixin.qq.com/sns/jscode2session", obtainSessionRequestParameters);
JSONObject obtainSessionResultJsonObject = JSONObject.fromObject(obtainSessionResult);
Validate.isTrue(!obtainSessionResultJsonObject.has("errcode"), obtainSessionResultJsonObject.optString("errmsg"));
apiRest = new ApiRest();
apiRest.setData(obtainSessionResultJsonObject);
apiRest.setMessage("处理成功!");
apiRest.setSuccessful(true);
} catch (Exception e) {
LogUtils.error("code换取session_key失败", controllerSimpleName, "obtainSessionWithJsCode", e, requestParameters);
apiRest = new ApiRest(e);
}
return GsonUtils.toJson(apiRest);
}
Aggregations