f8693dbb7491d2815a84cbecad35071232295dd3.svn-base 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.yihu.jkedu.action;
  2. import java.util.Map;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import net.sf.json.JSONObject;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import com.yihu.utils.ApiUtil;
  9. import com.yihu.utils.StringUtil;
  10. import com.yihu.utils.WxConfig;
  11. @Controller
  12. @RequestMapping("/weixin")
  13. public class WeiXinControl
  14. {
  15. @RequestMapping(value = "/getWeiXinConfig")
  16. public void getWeiXinConfig(HttpServletRequest request,
  17. HttpServletResponse response)throws Exception {
  18. response.setContentType("application/json;charset=UTF-8");
  19. String url = StringUtil.isEmpty(request.getParameter("url")) ? null : request.getParameter("url");
  20. String jsapi_ticket = StringUtil.isEmpty(request.getParameter("jsapi_ticket")) ? null : request.getParameter("jsapi_ticket");
  21. if(StringUtil.isEmpty(url)){
  22. response.getWriter().write(ApiUtil.jsonResult(-10000, "url不能为空,分享不了该文章").toString());
  23. return;
  24. }
  25. if(StringUtil.isEmpty(jsapi_ticket)){
  26. response.getWriter().write(ApiUtil.jsonResult(-10000, "jsapi_ticket不能为空,分享不了该文章").toString());
  27. return;
  28. }
  29. try{
  30. JSONObject config=WxConfig.getConfig(jsapi_ticket, url);
  31. JSONObject resultJson=new JSONObject();
  32. if(null!=config && config.size()>0){
  33. resultJson.put("Code", 10000);
  34. resultJson.put("Message", "成功");
  35. resultJson.put("Result", config);
  36. }else{
  37. resultJson.put("Code", -10000);
  38. resultJson.put("Message", "获取失败");
  39. resultJson.put("Result", config);
  40. }
  41. response.getWriter().write(resultJson.toString());
  42. return;
  43. }catch(Exception e){
  44. e.printStackTrace();
  45. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取微信认证异常").toString());
  46. return;
  47. }
  48. }
  49. }