wechatapplet.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.cnd3b.restcontroller.publicmethod.wechatapplet;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.cnd3b.common.Controller;
  4. import com.cnd3b.common.data.Row;
  5. import com.cnd3b.common.data.Rows;
  6. import com.cnd3b.common.data.SQLFactory;
  7. import com.cnd3b.utility.WebRequest;
  8. import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Calendar;
  11. public class wechatapplet extends Controller {
  12. /**
  13. * 构造函数
  14. *
  15. * @param content
  16. */
  17. public wechatapplet(JSONObject content) {
  18. super(content);
  19. }
  20. public String wechatappletLogin() {
  21. String code = content.getString("code");
  22. int type = content.getIntValue("type");
  23. String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=" + WechatDock_Enterprise.getMiniAppAccessToken(type) + "&code=" + code;
  24. // System.err.println(url);
  25. String response = new WebRequest().doGet(url);
  26. JSONObject object = JSONObject.parseObject(response);
  27. // System.err.println(object);
  28. int errcode = object.getIntValue("errcode");
  29. String errmsg = object.getString("errmsg");
  30. if (errcode != 0) {
  31. return getErrReturnObject().setErrMsg(errmsg).toString();
  32. }
  33. String userid = object.getString("UserId");
  34. SQLFactory sqlFactory = new SQLFactory(this, "查询账号");
  35. sqlFactory.addParameter("wechat_userid", userid);
  36. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  37. for (Row row : rows) {
  38. row.put("logintime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
  39. }
  40. if (rows.isEmpty()) {
  41. return getErrReturnObject().setErrMsg("未找到用户信息").toString();
  42. }
  43. return getSucReturnObject().setData(rows).toString();
  44. }
  45. }