Przeglądaj źródła

对接天天电竞用户

x1ongzhu 7 lat temu
rodzic
commit
b8671de81a

+ 6 - 0
log.txt

@@ -2020,3 +2020,9 @@ Caused by: java.net.UnknownHostException: microball.oss-cn-hangzhou.aliyuncs.com
 [2019-03-29 11:06:47] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-03-29 11:07:56] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-03-29 11:09:13] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 17:57:12] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 18:00:23] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 18:14:52] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 18:15:13] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 18:19:18] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2019-05-21 18:23:31] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.

+ 5 - 0
pom.xml

@@ -1032,6 +1032,11 @@
             <artifactId>leptonica-platform</artifactId>
             <version>1.77.0-1.4.4</version>
         </dependency>
+        <dependency>
+            <groupId>com.arronlong</groupId>
+            <artifactId>httpclientutil</artifactId>
+            <version>1.0.4</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 118 - 7
src/main/java/com/izouma/awesomeadmin/dao/UserInfoMapper.xml

@@ -34,6 +34,11 @@
         <result column="notice_flag" property="noticeFlag" jdbcType="CHAR"/>
         <result column="remind_flag" property="remindFlag" jdbcType="CHAR"/>
         <result column="create_flag" property="createFlag" jdbcType="CHAR"/>
+        <result column="ttdj_id" property="ttdjId" jdbcType="VARCHAR"/>
+        <result column="is_vip" property="isVip" jdbcType="BIT"/>
+        <result column="start_date" property="startDate" jdbcType="VARCHAR"/>
+        <result column="expire_date" property="expireDate" jdbcType="VARCHAR"/>
+        <result column="token" property="token" jdbcType="VARCHAR"/>
         <association property="departId" javaType="string" column="id"
                      select="com.izouma.awesomeadmin.dao.DepartInfoMapper.getUserDepartId"/>
         <association property="roleId" javaType="string" column="id"
@@ -44,7 +49,7 @@
         country, province, city, district, create_time, del_flag, money_coin, money_point,
         contacter, contact_phone, company_name, company_type, admin_flag, cash_pledge,
         approve_flag, store_flag, company_flag, approve_step, notice_flag, remind_flag,
-        create_flag
+        create_flag, ttdj_id, is_vip, start_date, expire_date, token
     </sql>
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
         select
@@ -53,9 +58,9 @@
         where id = #{id,jdbcType=INTEGER}
     </select>
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
-        delete
-        from sys_user
-        where id = #{id,jdbcType=INTEGER}
+        DELETE
+        FROM sys_user
+        WHERE id = #{id,jdbcType=INTEGER}
     </delete>
     <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.UserInfo" useGeneratedKeys="true"
             keyProperty="id">
@@ -160,6 +165,21 @@
             <if test="createFlag != null">
                 create_flag,
             </if>
+            <if test="ttdjId != null">
+                ttdj_id,
+            </if>
+            <if test="isVip != null">
+                is_vip,
+            </if>
+            <if test="startDate != null">
+                start_date,
+            </if>
+            <if test="expireDate != null">
+                expire_date,
+            </if>
+            <if test="token != null">
+                token,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">
@@ -261,6 +281,21 @@
             <if test="createFlag != null">
                 #{createFlag},
             </if>
+            <if test="ttdjId != null">
+                #{ttdjId},
+            </if>
+            <if test="isVip != null">
+                #{isVip},
+            </if>
+            <if test="startDate != null">
+                #{startDate},
+            </if>
+            <if test="expireDate != null">
+                #{expireDate},
+            </if>
+            <if test="token != null">
+                #{token},
+            </if>
         </trim>
     </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.UserInfo">
@@ -362,6 +397,21 @@
             <if test="createFlag != null">
                 create_flag = #{createFlag},
             </if>
+            <if test="ttdjId != null">
+                ttdj_id = #{ttdjId},
+            </if>
+            <if test="isVip != null">
+                is_vip = #{isVip},
+            </if>
+            <if test="startDate != null">
+                start_date = #{startDate},
+            </if>
+            <if test="expireDate != null">
+                expire_date = #{expireDate},
+            </if>
+            <if test="token != null">
+                token = #{token},
+            </if>
         </set>
         where id = #{id,jdbcType=INTEGER}
     </update>
@@ -459,6 +509,21 @@
             <if test="record.createFlag != null and !&quot;&quot;.equals(record.createFlag)">
                 and create_flag = #{record.createFlag}
             </if>
+            <if test="record.ttdjId != null and !&quot;&quot;.equals(record.ttdjId)">
+                and ttdj_id = #{record.ttdjId}
+            </if>
+            <if test="record.isVip != null and !&quot;&quot;.equals(record.isVip)">
+                and is_vip = #{record.isVip}
+            </if>
+            <if test="record.startDate != null and !&quot;&quot;.equals(record.startDate)">
+                and start_date = #{record.startDate}
+            </if>
+            <if test="record.expireDate != null and !&quot;&quot;.equals(record.expireDate)">
+                and expire_date = #{record.expireDate}
+            </if>
+            <if test="record.token != null and !&quot;&quot;.equals(record.token)">
+                and token = #{record.token}
+            </if>
 
             <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
@@ -563,10 +628,24 @@
             <if test="approveStep != null and !&quot;&quot;.equals(approveStep)">
                 and approve_step = #{approveStep}
             </if>
-
             <if test="createFlag != null and !&quot;&quot;.equals(createFlag)">
                 and create_flag = #{createFlag}
             </if>
+            <if test="ttdjId != null and !&quot;&quot;.equals(ttdjId)">
+                and ttdj_id = #{ttdjId}
+            </if>
+            <if test="isVip != null and !&quot;&quot;.equals(isVip)">
+                and is_vip = #{isVip}
+            </if>
+            <if test="startDate != null and !&quot;&quot;.equals(startDate)">
+                and start_date = #{startDate}
+            </if>
+            <if test="expireDate != null and !&quot;&quot;.equals(expireDate)">
+                and expire_date = #{expireDate}
+            </if>
+            <if test="token != null and !&quot;&quot;.equals(token)">
+                and token = #{token}
+            </if>
 
             <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                 <trim prefix="and (" suffix=")" prefixOverrides="OR">
@@ -643,6 +722,21 @@
             <if test="createFlag != null and !&quot;&quot;.equals(createFlag)">
                 and create_flag = #{createFlag}
             </if>
+            <if test="ttdjId != null and !&quot;&quot;.equals(ttdjId)">
+                and ttdj_id = #{ttdjId}
+            </if>
+            <if test="isVip != null and !&quot;&quot;.equals(isVip)">
+                and is_vip = #{isVip}
+            </if>
+            <if test="startDate != null and !&quot;&quot;.equals(startDate)">
+                and start_date = #{startDate}
+            </if>
+            <if test="expireDate != null and !&quot;&quot;.equals(expireDate)">
+                and expire_date = #{expireDate}
+            </if>
+            <if test="token != null and !&quot;&quot;.equals(token)">
+                and token = #{token}
+            </if>
         </where>
         LIMIT 1
     </select>
@@ -709,6 +803,21 @@
             <if test="createFlag != null and !&quot;&quot;.equals(createFlag)">
                 and create_flag = #{createFlag}
             </if>
+            <if test="ttdjId != null and !&quot;&quot;.equals(ttdjId)">
+                and ttdj_id = #{ttdjId}
+            </if>
+            <if test="isVip != null and !&quot;&quot;.equals(isVip)">
+                and is_vip = #{isVip}
+            </if>
+            <if test="startDate != null and !&quot;&quot;.equals(startDate)">
+                and start_date = #{startDate}
+            </if>
+            <if test="expireDate != null and !&quot;&quot;.equals(expireDate)">
+                and expire_date = #{expireDate}
+            </if>
+            <if test="token != null and !&quot;&quot;.equals(token)">
+                and token = #{token}
+            </if>
         </where>
         LIMIT 1
     </select>
@@ -732,8 +841,10 @@
     <select id="findUserByRoleName" resultType="java.lang.String">
         SELECT user_id
         FROM sys_user_role
-        WHERE FIND_IN_SET((SELECT id FROM sys_role WHERE enname = #{roleName}
-                                                     AND sys_role.del_flag = 'N'), role_id)
+        WHERE FIND_IN_SET((SELECT id
+                           FROM sys_role
+                           WHERE enname = #{roleName}
+                             AND sys_role.del_flag = 'N'), role_id)
     </select>
     <update id="delete">
         UPDATE sys_user SET del_flag = 'Y'

+ 49 - 0
src/main/java/com/izouma/awesomeadmin/model/UserInfo.java

@@ -83,6 +83,15 @@ public class UserInfo {
 
     private String createFlag;
 
+    private String ttdjId;
+
+    private Boolean isVip;
+
+    private String startDate;
+
+    private String expireDate;
+
+    private String token;
 
     public String getDepartId() {
         return departId;
@@ -364,5 +373,45 @@ public class UserInfo {
     public void setCreateFlag(String createFlag) {
         this.createFlag = createFlag;
     }
+
+    public String getTtdjId() {
+        return ttdjId;
+    }
+
+    public void setTtdjId(String ttdjId) {
+        this.ttdjId = ttdjId;
+    }
+
+    public Boolean getVip() {
+        return isVip;
+    }
+
+    public void setVip(Boolean vip) {
+        isVip = vip;
+    }
+
+    public String getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(String startDate) {
+        this.startDate = startDate;
+    }
+
+    public String getExpireDate() {
+        return expireDate;
+    }
+
+    public void setExpireDate(String expireDate) {
+        this.expireDate = expireDate;
+    }
+
+    public String getToken() {
+        return token;
+    }
+
+    public void setToken(String token) {
+        this.token = token;
+    }
 }
 

+ 1 - 1
src/main/java/com/izouma/awesomeadmin/service/UserInfoService.java

@@ -30,7 +30,7 @@ public interface UserInfoService {
 
     UserInfo login(String username, String password);
 
-    UserInfo loginSms(String phone, String code, String sessionId) throws UserInfoServiceImpl.LoginException;
+    UserInfo loginSms(String phone, String code) throws UserInfoServiceImpl.LoginException;
 
     UserInfo loginAppToken(String token);
 

+ 67 - 34
src/main/java/com/izouma/awesomeadmin/service/impl/UserInfoServiceImpl.java

@@ -8,6 +8,10 @@ import com.izouma.awesomeadmin.model.MemberCoin;
 import com.izouma.awesomeadmin.model.UserInfo;
 import com.izouma.awesomeadmin.service.OSSFileService;
 import com.izouma.awesomeadmin.service.UserInfoService;
+import com.izouma.awesomeadmin.ttdjApi.LoginResponse;
+import com.izouma.awesomeadmin.ttdjApi.TTDJApiUtil;
+import com.izouma.awesomeadmin.ttdjApi.TTResponse;
+import com.izouma.awesomeadmin.ttdjApi.UserInfoResponse;
 import com.izouma.awesomeadmin.util.MD5Util;
 import com.izouma.awesomeadmin.util.PropertiesFileLoader;
 import com.izouma.awesomeadmin.util.WeixinUtil;
@@ -25,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.crypto.SecretKey;
+import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.HttpURLConnection;
@@ -39,26 +44,25 @@ import java.util.*;
 @Service
 public class UserInfoServiceImpl implements UserInfoService {
 
-    private static Logger logger = Logger.getLogger(UserInfoServiceImpl.class);
-    private RongCloud rongCloud = RongCloud.getInstance(PropertiesFileLoader.getProperties("rongyunappkey"), PropertiesFileLoader.getProperties("rongyunappsecret"));
+    private static Logger    logger    = Logger.getLogger(UserInfoServiceImpl.class);
+    private        RongCloud rongCloud = RongCloud.getInstance(PropertiesFileLoader.getProperties("rongyunappkey"), PropertiesFileLoader.getProperties("rongyunappsecret"));
 
     @Autowired
-    private UserInfoMapper userInfoMapper;
+    private UserInfoMapper     userInfoMapper;
     @Autowired
-    private SysRoleMapper sysRoleMapper;
+    private SysRoleMapper      sysRoleMapper;
     @Autowired
-    private DepartInfoMapper departInfoMapper;
+    private DepartInfoMapper   departInfoMapper;
     @Autowired
-    private SysAppTokenMapper sysAppTokenMapper;
-
+    private SysAppTokenMapper  sysAppTokenMapper;
     @Autowired
-    private OSSFileService ossFileService;
-
+    private OSSFileService     ossFileService;
     @Autowired
-    private AlipayTempMapper alipayTempMapper;
-
+    private AlipayTempMapper   alipayTempMapper;
     @Autowired
-    private MemberCoinMapper memberCoinMapper;
+    private MemberCoinMapper   memberCoinMapper;
+    @Autowired
+    private HttpServletRequest request;
 
     @Override
     public List<UserInfo> getUserInfoList(UserInfo record) {
@@ -318,35 +322,64 @@ public class UserInfoServiceImpl implements UserInfoService {
 
 
     @Override
-    public UserInfo loginSms(String phone, String code, String sessionId) throws LoginException {
+    public UserInfo loginSms(String phone, String code) throws LoginException {
         logger.info("loginSms");
-        SMSVerifyCodeResult sMSVerifyCodeResult;
+
+        TTDJApiUtil ttdjApiUtil = new TTDJApiUtil(request.getHeader("clientType"));
+        LoginResponse response = ttdjApiUtil.login(phone, code);
+        if (response == null) {
+            throw new LoginException("登录失败");
+        }
+        if (!response.isSuccess()) {
+            throw new LoginException(response.getMsg());
+        }
+        String ttdjId = response.getData().getUserId();
+        String token = response.getData().getToken();
+        UserInfoResponse ttUserInfo = null;
         try {
-            sMSVerifyCodeResult = rongCloud.sms.verifyCode(sessionId, code);
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new LoginException("验证码错误");
+            ttUserInfo = ttdjApiUtil.getUserInfo(ttdjId, token);
+        } catch (Exception ignored) {
         }
-        if (200 == sMSVerifyCodeResult.getCode()) {
-            Boolean success = sMSVerifyCodeResult.getSuccess();
-            if (success) {
-                UserInfo userInfo = new UserInfo();
+        int isVip = 0;
+        String startDate = null;
+        String expireDate = null;
+        if (ttUserInfo != null) {
+            isVip =   ttUserInfo.getData().getIsVip();
+            startDate =  ttUserInfo.getData().getStartDate();
+            expireDate = ttUserInfo.getData().getExpireData();
+        }
+        UserInfo userInfo = new UserInfo();
+        userInfo.setPhone(phone);
+        userInfo = getUserInfo(userInfo);
+        try {
+            if (userInfo == null) {
+                userInfo = new UserInfo();
                 userInfo.setPhone(phone);
-                userInfo = getUserInfo(userInfo);
-                if (userInfo == null) {
-                    userInfo = new UserInfo();
-                    userInfo.setPhone(phone);
-                    userInfo.setUsername(phone);
-                    userInfo.setNickname(phone);
-                    userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png");
-                    if (!createUserInfo(userInfo)) {
-                        throw new LoginException("登录失败");
-                    }
+                userInfo.setUsername(phone);
+                userInfo.setNickname(phone);
+                userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png");
+                userInfo.setTtdjId(ttdjId);
+                userInfo.setToken(token);
+                userInfo.setVip(isVip == 1);
+                userInfo.setStartDate(startDate);
+                userInfo.setExpireDate(expireDate);
+                if (!createUserInfo(userInfo)) {
+                    throw new LoginException("登录失败");
                 }
-                return userInfo;
+            } else {
+                userInfo.setTtdjId(ttdjId);
+                userInfo.setToken(token);
+                userInfo.setVip(isVip == 1);
+                userInfo.setStartDate(startDate);
+                userInfo.setExpireDate(expireDate);
+                updateUserInfo(userInfo);
             }
+
+            return userInfo;
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new LoginException("登录失败");
         }
-        throw new LoginException("验证码错误");
     }
 
     @Override

+ 1 - 1
src/main/java/com/izouma/awesomeadmin/shiro/PhoneCodeRealm.java

@@ -14,7 +14,7 @@ public class PhoneCodeRealm extends BaseRealm {
         UserInfo userInfo = null;
         PhoneCodeToken phoneCodeToken = (PhoneCodeToken) token;
         try {
-            userInfo = userInfoService.loginSms(phoneCodeToken.getPhone(), phoneCodeToken.getCode(), phoneCodeToken.getSessionId());
+            userInfo = userInfoService.loginSms(phoneCodeToken.getPhone(), phoneCodeToken.getCode());
             return new SimpleAuthenticationInfo(userInfo, token.getCredentials(), this.getName());
         } catch (UserInfoServiceImpl.LoginException e) {
             throw new AuthenticationException(e.getMessage());

+ 9 - 4
src/main/java/com/izouma/awesomeadmin/shiro/PhoneCodeToken.java

@@ -6,10 +6,10 @@ import org.apache.shiro.authc.RememberMeAuthenticationToken;
 public class PhoneCodeToken implements HostAuthenticationToken, RememberMeAuthenticationToken {
 
     private boolean rememberMe;
-    private String host;
-    private String phone;
-    private String code;
-    private String sessionId;
+    private String  host;
+    private String  phone;
+    private String  code;
+    private String  sessionId;
 
     public PhoneCodeToken(String phone, String code, String sessionId) {
         this.phone = phone;
@@ -17,6 +17,11 @@ public class PhoneCodeToken implements HostAuthenticationToken, RememberMeAuthen
         this.sessionId = sessionId;
     }
 
+    public PhoneCodeToken(String phone, String code) {
+        this.phone = phone;
+        this.code = code;
+    }
+
     public void setRememberMe(boolean rememberMe) {
         this.rememberMe = rememberMe;
     }

+ 34 - 0
src/main/java/com/izouma/awesomeadmin/ttdjApi/LoginResponse.java

@@ -0,0 +1,34 @@
+package com.izouma.awesomeadmin.ttdjApi;
+
+public class LoginResponse extends TTResponse {
+    private LoginData data;
+
+    public LoginData getData() {
+        return data;
+    }
+
+    public void setData(LoginData data) {
+        this.data = data;
+    }
+
+   public class LoginData {
+        private String userId;
+        private String token;
+
+        public String getUserId() {
+            return userId;
+        }
+
+        public void setUserId(String userId) {
+            this.userId = userId;
+        }
+
+        public String getToken() {
+            return token;
+        }
+
+        public void setToken(String token) {
+            this.token = token;
+        }
+    }
+}

+ 119 - 0
src/main/java/com/izouma/awesomeadmin/ttdjApi/TTDJApiUtil.java

@@ -0,0 +1,119 @@
+package com.izouma.awesomeadmin.ttdjApi;
+
+import com.arronlong.httpclientutil.HttpClientUtil;
+import com.arronlong.httpclientutil.common.HttpConfig;
+import com.arronlong.httpclientutil.exception.HttpProcessException;
+import com.google.gson.Gson;
+import com.izouma.awesomeadmin.service.impl.AlipayTempServiceImpl;
+import net.sf.json.JSONObject;
+import org.apache.commons.collections.map.ListOrderedMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.Header;
+import org.apache.http.message.BasicHeader;
+import org.apache.log4j.Logger;
+import org.springframework.util.DigestUtils;
+
+import java.util.*;
+
+public class TTDJApiUtil {
+    private static Logger logger = Logger.getLogger(AlipayTempServiceImpl.class);
+    private        String clientType;
+
+    public TTDJApiUtil(String clientType) {
+        this.clientType = clientType;
+    }
+
+    public TTResponse sendSms(String mobile) {
+        Map<String, String> body = new HashMap<>();
+        body.put("mobile", mobile);
+        body.put("sendType", "3");
+        try {
+            String res = removeEmptyValue(post("http://test.ttdj.ttdianjing.com/user/sendCaptcha", body, null));
+            Gson gson = new Gson();
+            return gson.fromJson(res, TTResponse.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public LoginResponse login(String mobile, String captcha) {
+        Map<String, String> body = new HashMap<>();
+        body.put("mobile", mobile);
+        body.put("captcha", captcha);
+        try {
+            String res = removeEmptyValue(post("http://test.ttdj.ttdianjing.com/user/login", body, null));
+            Gson gson = new Gson();
+            return gson.fromJson(res, LoginResponse.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public UserInfoResponse getUserInfo(String userId, String token) {
+        Map<String, String> body = new HashMap<>();
+        body.put("userId", userId);
+        try {
+            String res = removeEmptyValue(post("http://test.ttdj.ttdianjing.com/user/queryUserVip", body, token));
+            Gson gson = new Gson();
+            return gson.fromJson(res, UserInfoResponse.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private String post(String url, Map<String, String> body, String token) {
+        String appKey = "1557281556ibPS1wFSicpPkbem8eW1";
+        String sign = getSign(body);
+        List<Header> headers = new ArrayList<>();
+        headers.add(new BasicHeader("app_key", appKey));
+        headers.add(new BasicHeader("sign", sign));
+        headers.add(new BasicHeader("client_type", clientType));
+        if (StringUtils.isNotEmpty(token)) {
+            headers.add(new BasicHeader("token", token));
+        }
+        HttpConfig config = HttpConfig.custom()
+                .url(url)
+                .headers(headers.toArray(new Header[0]))
+                .json(JSONObject.fromObject(body).toString());
+        try {
+            String res = HttpClientUtil.post(config);
+            logger.info(res);
+            return res;
+        } catch (HttpProcessException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private String getSign(Map<String, String> map) {
+        String appKey = "1557281556ibPS1wFSicpPkbem8eW1";
+        String appSecret = "ecO8lX8W8bQp8vQ9HVhE93t2";
+        List<String> list = new ArrayList<>();
+        map.forEach((key, value) -> {
+            if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) {
+                list.add(key + "=" + value);
+            }
+        });
+        list.sort(String::compareTo);
+        String s = StringUtils.join(list, "&") + "&" + appSecret;
+        s = DigestUtils.md5DigestAsHex(s.getBytes());
+        return s;
+    }
+
+    private String removeEmptyValue(String str) {
+        try {
+            JSONObject jsonObject = JSONObject.fromObject(str);
+            String data = jsonObject.getString("data");
+            if (StringUtils.isEmpty(data)) {
+                jsonObject.remove("data");
+            }
+            return jsonObject.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+}

+ 41 - 0
src/main/java/com/izouma/awesomeadmin/ttdjApi/TTResponse.java

@@ -0,0 +1,41 @@
+package com.izouma.awesomeadmin.ttdjApi;
+
+
+public class TTResponse {
+    private int                 code;
+    private boolean             success;
+    private String              msg;
+    private String              extra;
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public String getExtra() {
+        return extra;
+    }
+
+    public void setExtra(String extra) {
+        this.extra = extra;
+    }
+}

+ 52 - 0
src/main/java/com/izouma/awesomeadmin/ttdjApi/UserInfoResponse.java

@@ -0,0 +1,52 @@
+package com.izouma.awesomeadmin.ttdjApi;
+
+public class UserInfoResponse extends TTResponse {
+    private UserData data;
+
+    public UserData getData() {
+        return data;
+    }
+
+    public void setData(UserData data) {
+        this.data = data;
+    }
+
+    public class UserData {
+        private String userId;
+        private String startDate;
+        private String expireData;
+        private int    isVip;
+
+        public String getUserId() {
+            return userId;
+        }
+
+        public void setUserId(String userId) {
+            this.userId = userId;
+        }
+
+        public String getStartDate() {
+            return startDate;
+        }
+
+        public void setStartDate(String startDate) {
+            this.startDate = startDate;
+        }
+
+        public String getExpireData() {
+            return expireData;
+        }
+
+        public void setExpireData(String expireData) {
+            this.expireData = expireData;
+        }
+
+        public int getIsVip() {
+            return isVip;
+        }
+
+        public void setIsVip(int isVip) {
+            this.isVip = isVip;
+        }
+    }
+}

+ 4 - 5
src/main/java/com/izouma/awesomeadmin/web/AuthenticationController.java

@@ -86,7 +86,7 @@ public class AuthenticationController {
                               HttpServletRequest request) {
         ModelAndView result = new ModelAndView(new MappingJackson2JsonView());
         UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
-        Map<String, Object> map = login(usernamePasswordToken, remember, requireToken, 3, request, response);
+        Map<String, Object> map = login(usernamePasswordToken, remember, requireToken, 30, request, response);
         result.addAllObjects(map);
         return result;
     }
@@ -95,7 +95,6 @@ public class AuthenticationController {
     @ResponseBody
     public ModelAndView loginBySms(@RequestParam("phone") String phone,
                                    @RequestParam("code") String code,
-                                   @RequestParam("sessionId") String sessionId,
                                    @RequestParam(value = "remember", required = false, defaultValue = "false") boolean remember,
                                    @RequestParam(value = "requireToken", required = false, defaultValue = "false") boolean requireToken,
                                    HttpServletRequest request,
@@ -104,8 +103,8 @@ public class AuthenticationController {
         //String rand = (String) request.getSession(true).getAttribute("aliMsgCode");
 
         ModelAndView result = new ModelAndView(new MappingJackson2JsonView());
-        PhoneCodeToken phoneCodeToken = new PhoneCodeToken(phone, code, sessionId);
-        Map<String, Object> map = login(phoneCodeToken, remember, requireToken, 3, request, response);
+        PhoneCodeToken phoneCodeToken = new PhoneCodeToken(phone, code);
+        Map<String, Object> map = login(phoneCodeToken, remember, requireToken, 30, request, response);
         result.addAllObjects(map);
         return result;
     }
@@ -176,7 +175,7 @@ public class AuthenticationController {
                 .setSubject(userInfo.getId().toString())
                 .signWith(key);
         if (expireDays > 0) {
-            Date date = new Date(System.currentTimeMillis() + (expireDays * 24 * 60 * 60 * 1000));
+            Date date = new Date(System.currentTimeMillis() + (expireDays * 24L * 60 * 60 * 1000));
             jwt.setExpiration(date);
         }
         String token = jwt.compact();

+ 12 - 3
src/main/java/com/izouma/awesomeadmin/web/UserInfoController.java

@@ -6,6 +6,8 @@ import com.izouma.awesomeadmin.dto.Result;
 import com.izouma.awesomeadmin.model.UserInfo;
 import com.izouma.awesomeadmin.service.DepartInfoService;
 import com.izouma.awesomeadmin.service.UserInfoService;
+import com.izouma.awesomeadmin.ttdjApi.TTDJApiUtil;
+import com.izouma.awesomeadmin.ttdjApi.TTResponse;
 import com.izouma.awesomeadmin.util.ExportExcelUtil;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.SecurityUtils;
@@ -33,7 +35,9 @@ import java.util.Map;
 public class UserInfoController {
 
     @Autowired
-    private UserInfoService userInfoService;
+    private UserInfoService    userInfoService;
+    @Autowired
+    private HttpServletRequest request;
 
     /**
      * <p>获取全部记录。</p>
@@ -214,7 +218,6 @@ public class UserInfoController {
             return new Result(false, "手机号已存在");
         }
 
-
         userInfo.setNickname(userInfo.getUsername());
         userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png");
 
@@ -227,6 +230,12 @@ public class UserInfoController {
         }
     }
 
-
+    @RequestMapping(value = "/sendSms", method = RequestMethod.POST)
+    @ResponseBody
+    public TTResponse sendSms(String mobile) {
+        String clientType = request.getHeader("clientType");
+        TTDJApiUtil ttdjApiUtil = new TTDJApiUtil(clientType);
+        return ttdjApiUtil.sendSms(mobile);
+    }
 }
 

+ 2 - 2
src/main/resources/properties/jdbc.properties

@@ -1,9 +1,9 @@
 jdbc.driverClassName=org.gjt.mm.mysql.Driver
 
 #外网地址
-jdbc.url=jdbc:mysql://120.55.131.232:3306/dianjinghudong
+jdbc.url=jdbc:mysql://120.55.131.232:3306/weidianjing
 jdbc.username=dianjinghudong
 jdbc.password=1qaz!QAZ
-jdbc.databaseName=dianjinghudong
+jdbc.databaseName=weidianjing
 
 

+ 3 - 1
src/main/webapp/WEB-INF/web.xml

@@ -39,6 +39,9 @@
     <listener>
         <listener-class>com.izouma.awesomeadmin.container.StartupListener</listener-class>
     </listener>
+    <listener>
+        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+    </listener>
     <filter>
         <filter-name>CharacterEncodingFilter</filter-name>
         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
@@ -80,5 +83,4 @@
     </filter-mapping>
 
 
-
 </web-app>

+ 101 - 0
src/test/java/ttapiTets.java

@@ -0,0 +1,101 @@
+import com.arronlong.httpclientutil.HttpClientUtil;
+import com.arronlong.httpclientutil.common.HttpConfig;
+import com.arronlong.httpclientutil.exception.HttpProcessException;
+import com.drew.lang.StringUtil;
+import net.sf.json.JSONObject;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.Header;
+import org.apache.http.message.BasicHeader;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.GenericXmlContextLoader;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.DigestUtils;
+
+import java.util.*;
+import java.util.function.BiConsumer;
+
+@RunWith(value = SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)
+@Transactional
+public class ttapiTets {
+    @Test
+    public void testSms() {
+        String appKey = "1557281556ibPS1wFSicpPkbem8eW1";
+        Map<String, String> body = new HashMap<>();
+        body.put("mobile", "15077886171");
+        body.put("sendType", "3");
+        String sign = getSign(body);
+        List<Header> headers = new ArrayList<>();
+        headers.add(new BasicHeader("app_key", appKey));
+        headers.add(new BasicHeader("sign", sign));
+        headers.add(new BasicHeader("client_type", "android"));
+        HttpConfig config = HttpConfig.custom()
+                .url("http://test.ttdj.ttdianjing.com/user/sendCaptcha")
+                .headers(headers.toArray(new Header[0]))
+                .json(JSONObject.fromObject(body).toString());
+        try {
+            String html = HttpClientUtil.post(config);
+            System.out.println(html);
+        } catch (HttpProcessException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testLogin() {
+        Map<String, String> body = new HashMap<>();
+        body.put("mobile", "15077886171");
+        body.put("captcha", "665975");
+        String res = post("http://test.ttdj.ttdianjing.com/user/login", body, null);
+        System.out.println(res);
+    }
+
+    @Test
+    public void testUserInfo() {
+        Map<String, String> body = new HashMap<>();
+        body.put("userId", "640285253");
+        String res = post("http://test.ttdj.ttdianjing.com/user/queryUserVip", body, "5843C6B30BE02B91E5186A38817F6DF0B357A0FC9083F08F6A1B3B15E0C63541A3BBC05BDCB263D355FC88752301AAC98A136AD16D32E58FCD912BD151F0A662E8C7DE6DB8EB9E5DA177B2037097E1FE2CE5C8475A2F2E7D21E6EF3412934117");
+        System.out.println(res);
+    }
+
+    private String post(String url, Map<String, String> body, String token) {
+        String appKey = "1557281556ibPS1wFSicpPkbem8eW1";
+        String sign = getSign(body);
+        List<Header> headers = new ArrayList<>();
+        headers.add(new BasicHeader("app_key", appKey));
+        headers.add(new BasicHeader("sign", sign));
+        headers.add(new BasicHeader("client_type", "android"));
+        if (StringUtils.isNotEmpty(token)) {
+            headers.add(new BasicHeader("token", token));
+        }
+        HttpConfig config = HttpConfig.custom()
+                .url(url)
+                .headers(headers.toArray(new Header[0]))
+                .json(JSONObject.fromObject(body).toString());
+        try {
+            return HttpClientUtil.post(config);
+        } catch (HttpProcessException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private String getSign(Map<String, String> map) {
+        String appKey = "1557281556ibPS1wFSicpPkbem8eW1";
+        String appSecret = "ecO8lX8W8bQp8vQ9HVhE93t2";
+        List<String> list = new ArrayList<>();
+        map.forEach((key, value) -> {
+            if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) {
+                list.add(key + "=" + value);
+            }
+        });
+        list.sort(String::compareTo);
+        String s = StringUtils.join(list, "&") + "&" + appSecret;
+        s = DigestUtils.md5DigestAsHex(s.getBytes());
+        System.out.println(s);
+        return s;
+    }
+}