| | |
| | | import java.util.*;
|
| | | import java.util.Map.Entry;
|
| | |
|
| | | import cn.hutool.http.HttpUtil;
|
| | | import com.smtaiserver.smtaiserver.weixinLogin.WeChatUtils;
|
| | | import org.apache.commons.text.similarity.JaccardSimilarity;
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | | import org.springframework.boot.configurationprocessor.json.JSONException;
|
| | | import org.springframework.web.servlet.ModelAndView;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
|
| | |
| | | jsonWr.addKeyValue("sex", recUser.getString("user_sex"));
|
| | | jsonWr.addKeyValue("email", recUser.getString("user_email"));
|
| | | jsonWr.addKeyValue("note", recUser.getString("note"));
|
| | | if (recUser.getString("weixin_nickname")!=null)
|
| | | jsonWr.addKeyValue("weixin_nikename",recUser.getString("weixin_nickname") );
|
| | | boolean b1 = recUser.getString("weixin_openid") != null;
|
| | | jsonWr.addKeyValue("weixin_openid",b1);
|
| | | jsonWr.addKeyValue("web_login", "Y".equals(recUser.getString("web_login")));
|
| | | |
| | | return tranReq.returnJson(jsonWr); |
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | |
|
| | | public ModelAndView loginSMS(SMTAIServerRequest tranReq) throws Exception
|
| | |
| | | if (weixinCode != null) {
|
| | | Map<String, String> accessTokenMap = WeChatUtils.getAccessToken(weixinCode);
|
| | | String openid = accessTokenMap.get("openid");
|
| | | String accessToken = accessTokenMap.get("access_token");
|
| | | String nikename = getUserInfo(accessToken, openid);
|
| | |
|
| | | if (openid == null || openid.isEmpty()) {
|
| | | return tranReq.returnJsonState(false, "登录失败, 无效的微信二维码", null);
|
| | |
| | | if (userByOpenid.getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "登录失败, 请绑定账号", null);
|
| | | }
|
| | |
|
| | | // 获取用户名和密码
|
| | | username = userByOpenid.getRecord(0).getString("user_name");
|
| | | password = userByOpenid.getRecord(0).getString("user_pass");
|
| | | db.executeSQL("UPDATE sys_user_info SET weixin_nickname=? WHERE user_name=?", new Object[] {
|
| | | nikename,
|
| | | username
|
| | | });
|
| | | is_weixin=true;
|
| | | }
|
| | |
|
| | |
| | | client
|
| | | });
|
| | | tranReq.setSessionAttribute("login_from", client);
|
| | | |
| | |
|
| | | return loginUser(db, recs.getRecord(0), updateLoginFlag, tranReq);
|
| | | }
|
| | | finally
|
| | |
| | | }
|
| | |
|
| | | }
|
| | | |
| | | public ModelAndView getLLMList(SMTAIServerRequest tranReq) throws Exception |
| | |
|
| | | public static String getUserInfo(String accessToken, String openId) throws JSONException {
|
| | | // 拼接请求地址
|
| | | String requestUrl =
|
| | | "https://api.weixin.qq.com/sns/userinfo?access_token="
|
| | | + accessToken
|
| | | + "&openid="
|
| | | + openId
|
| | | + "&lang=zh_CN";
|
| | | String result = HttpUtil.get(requestUrl);
|
| | | Json.Reader reader = new Json.Reader();
|
| | | Json read = (Json) reader.read(result, null);
|
| | | // JSONObject jsonObject = new JSONObject(result);
|
| | | return read.safeGetStr("nickname", null);
|
| | | }
|
| | |
|
| | | public ModelAndView getLLMList(SMTAIServerRequest tranReq) throws Exception
|
| | | {
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | jsonWr.beginArray("llm_list");
|
| | |
| | |
|
| | | }
|
| | |
|
| | | public ModelAndView userBindingWeChatAccount(SMTAIServerRequest tranReq) throws Exception {
|
| | | String weixinCode = tranReq.convParamToString("weixin_code", true);
|
| | | String userName = tranReq.convParamToString("user_name", true);
|
| | | Map<String, String> accessTokenMap = WeChatUtils.getAccessToken(weixinCode);
|
| | | String openid = accessTokenMap.get("openid");
|
| | |
|
| | | if (openid == null || openid.isEmpty()) {
|
| | | return tranReq.returnJsonState(false, "绑定失败, 无效的微信二维码", null);
|
| | | }
|
| | | try (SMTDatabase db = SMTAIServerApp.getApp().allocDatabase()) {
|
| | | int executeSQL = db.executeSQL("UPDATE sys_user_info set weixin_openid =? where user_name=?", new Object[]{openid, userName});
|
| | | }
|
| | | return tranReq.returnJsonState(true, "绑定成功", null);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 绑定微信openid和nickname
|
| | | * @param tranReq
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public ModelAndView userBindingWeChatAccount(SMTAIServerRequest tranReq) throws Exception {
|
| | | String weixinCode = tranReq.convParamToString("weixin_code", true);
|
| | | String userName;
|
| | | String nikcname;
|
| | | try (SMTDatabase db = SMTAIServerApp.getApp().allocDatabase()) {
|
| | | String loginUserId = tranReq.getLoginUserId();
|
| | | DBRecords dbRecords =
|
| | | db.querySQL("select * from sys_user_info where user_id =?", new Object[] {loginUserId});
|
| | | if (dbRecords.getRowCount() > 0) {
|
| | | userName = (String) dbRecords.getRecords().get(0).getValue("user_name");
|
| | | } else {
|
| | | return tranReq.returnJsonState(false, "绑定失败, 用户信息异常", null);
|
| | | }
|
| | | Map<String, String> accessTokenMap = WeChatUtils.getAccessToken(weixinCode);
|
| | | String openid = accessTokenMap.get("openid");
|
| | | String accessToken = accessTokenMap.get("access_token");
|
| | | nikcname = getUserInfo(accessToken, openid);
|
| | | if (openid == null || openid.isEmpty()) {
|
| | | return tranReq.returnJsonState(false, "绑定失败, 无效的微信二维码", null);
|
| | | }
|
| | | db.executeSQL(
|
| | | "UPDATE sys_user_info set weixin_openid =?,weixin_nickname=? where user_name=?",
|
| | | new Object[] {openid, nikcname, userName});
|
| | | }
|
| | | return tranReq.returnJsonState(true, "绑定成功", nikcname);
|
| | | }
|
| | | }
|