Commit c38fe785 authored by 张大伟's avatar 张大伟

增加微信授权

parent 9be839fb
package org.rcisoft.wechat;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.rcisoft.wechat.service.WxPortalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
/**
* 网页授权微信回调接口
*
* @author David
*/
@Controller
......@@ -20,6 +26,9 @@ public class WechatRedirectController {
@Resource
private WxPortalService service;
@Autowired
private WxMpService wxService;
@RequestMapping(value = {"/index"})
public String index(String code) {
......@@ -34,4 +43,20 @@ public class WechatRedirectController {
}
}
@RequestMapping(value = {"/getConfig"})
@ResponseBody
public Map<String, Object> getConfig(String url) {
try {
WxJsapiSignature wxJsapiSignature = service.getJsApiTicket(url);
Map<String, Object> map = new HashMap<>(4);
map.put("timestamp", wxJsapiSignature.getTimestamp());
map.put("nonceStr", wxJsapiSignature.getNonceStr());
map.put("signature", wxJsapiSignature.getSignature());
map.put("appId", wxJsapiSignature.getAppId());
return map;
} catch (WxErrorException e) {
e.printStackTrace();
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment