修改文件名

master
qi_liang 6 years ago
parent 96214af01a
commit 291fc81385
  1. 17
      src/main/java/com/lq/wechat/util/WechatUserUtil.java
  2. 27
      src/main/java/com/lq/wechat/util/accessToken/AccessTokenUtil.java
  3. 1
      src/main/java/com/lq/wechat/web/WechatController.java
  4. 2
      src/main/resources/dev/jdbc.properties
  5. 2
      src/main/resources/dev/redis.properties
  6. 91
      src/main/resources/mybatis/mapping/WechatUserDao.xml
  7. 31
      src/main/resources/pro/jdbc.properties
  8. 2
      src/main/resources/spring-mybatis-config.xml

@ -1,5 +1,10 @@
package com.lq.wechat.util;
import com.alibaba.fastjson.JSONObject;
import com.lq.code.util.HttpKit;
import com.lq.code.util.HttpsClient;
import com.lq.entity.WechatUser;
/**
* @Author: qi
* @Description: 微信公众号-用户相关的工具类
@ -15,4 +20,16 @@ public class WechatUserUtil {
* 批量获取用户基本信息 (post请求)
*/
public static final String BATCHGET_USER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN";
public static String getWechatUserStr(String accessToken,String openId){
String url = GET_USER_INFO_URL.replace("ACCESS_TOKEN",accessToken).replace("OPENID","openId");
String result = HttpKit.get(url);
return result;
};
public static WechatUser getWechatUser(String accessToken,String openId){
String result = getWechatUserStr(accessToken,openId);
WechatUser wechatUser = JSONObject.parseObject(result,WechatUser.class);
return wechatUser;
}
}

@ -2,6 +2,7 @@ package com.lq.wechat.util.accessToken;
import com.alibaba.fastjson.JSONObject;
import com.lq.code.util.HttpKit;
import com.lq.code.util.StringUtil;
import com.lq.dao.WechatAccesstokenDao;
import com.lq.entity.WechatAccessToken;
import com.lq.entity.WechatInfo;
@ -13,6 +14,7 @@ import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* Created by qi_liang on 2018/5/31.
@ -28,9 +30,13 @@ public class AccessTokenUtil {
public final static String APPID ="wx76ca7130852c4baa";
public final static String APPSECRET = "d87125562b8e60618bc7b3120dfe3583";
/**
* 微信公众号access_token在reids的生命周期时间(单位)
*/
public final static long DEFAULT_TIME = 7000L;
@Autowired
private RedisTemplate<String,Object> redisTemplate;
private RedisTemplate<String,String> redisTemplate;
public static String getAccessToken(String appid,String appsecret){
String url = ACCESS_TOKEN_URL.replace("APPID",appid).replace("APPSECRET",appsecret);
@ -38,19 +44,16 @@ public class AccessTokenUtil {
return resultStr;
}
public static AccessToken getAccessToken(WechatInfo wechatInfo){
AccessToken accessToken = null;
if (wechatInfo!=null){
public String getAccessToken(WechatInfo wechatInfo){
String accessTokenStr = redisTemplate.opsForValue().get(wechatInfo.getWechatOpenId());
if (wechatInfo!=null&& StringUtil.isNull(accessTokenStr)){
String result = getAccessToken(wechatInfo.getAppId(),wechatInfo.getAppSecpet());
accessToken = JSONObject.parseObject(result,AccessToken.class);
AccessToken accessToken = JSONObject.parseObject(result,AccessToken.class);
accessTokenStr = accessToken.getAccess_token();
redisTemplate.opsForValue().set(wechatInfo.getWechatOpenId(),accessTokenStr,DEFAULT_TIME, TimeUnit.SECONDS);
}
return accessToken;
}
public static WechatAccessToken accessTokenToWechatAccessToken(WechatInfo wechatInfo,AccessTokenAdapter accessTokenAdapter){
AccessToken accessToken = getAccessToken(wechatInfo);
return accessTokenAdapter.adapter(accessToken);
return accessTokenStr;
}
public static void main(String[] args) {

@ -44,7 +44,6 @@ public class WechatController extends BaseController {
//用户-消息内容
public static final String WECHAT_CONTENT_KEY = "Content";
@Autowired
private WechatInfoService wechatInfoService;
@Autowired

@ -1,6 +1,6 @@
#--------- jdbc 配置---------
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
jdbc.url=jdbc:mysql://192.168.31.19:3306/ssm?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
jdbc.user=root
jdbc.password=mysql
#--------数据库连接池配置 -------

@ -1,4 +1,4 @@
redis.host=127.0.0.1
redis.host=192.168.31.19
redis.port=6379
redis.pass=
redis.timeout=-1

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lq.dao.WechatUserDao">
<!-- namespace命名空间,作用是对sql进行分类化管理,理解sql隔离 -->
<!-- 注意:使用mapper代理方法开发 ,namespace有着特殊作用-->
<sql id="column_list">
country,unionid,sybscribe_scene,qr_scene,qr_scene_str,subscribe_time,city,tagid_id,open_id,nick_name,sex,groupid,language,remark,province,head_img_url,wechat_info_id,id,status
</sql>
<select id="findOne" resultType="com.lq.entity.WechatUser" parameterType="long">
SELECT <include refid="column_list"/>
FROM wechat_user
WHERE id=#{id} AND status = 1
</select>
<select id="findAll" resultType="com.lq.entity.WechatUser">
SELECT <include refid="column_list"/>
FROM wechat_user
WHERE status = 1
</select>
<select id="count" resultType="int">
SELECT count(id)
FROM wechat_user
WHERE status = 1
</select>
<insert id="save" parameterType="com.lq.entity.WechatUser" useGeneratedKeys="true" keyProperty="id">
<selectKey keyProperty="id" order="AFTER" resultType="Long">
SELECT LAST_INSERT_ID()
</selectKey>
INSERT INTO
wechat_user(country,unionid,sybscribe_scene,qr_scene,qr_scene_str,subscribe_time,city,tagid_id,open_id,nick_name,sex,groupid,language,remark,province,head_img_url,wechat_info_id,id,status)
VALUES
(
#{country},#{unionid},#{sybscribeScene},#{qrScene},#{qrSceneStr},#{subscribeTime},#{city},#{tagidId},#{openId},#{nickName},#{sex},#{groupid},#{language},#{remark},#{province},#{headImgUrl},#{wechatInfoId},#{id},#{status}
)
</insert>
<update id="update" parameterType="com.lq.entity.WechatUser">
UPDATE
wechat_user
<trim prefix="set" suffixOverrides=",">
<if test="country!=null">country=#{country},</if>
<if test="unionid!=null">unionid=#{unionid},</if>
<if test="sybscribeScene!=null">sybscribe_scene=#{sybscribeScene},</if>
<if test="qrScene!=null">qr_scene=#{qrScene},</if>
<if test="qrSceneStr!=null">qr_scene_str=#{qrSceneStr},</if>
<if test="subscribeTime!=null">subscribe_time=#{subscribeTime},</if>
<if test="city!=null">city=#{city},</if>
<if test="tagidId!=null">tagid_id=#{tagidId},</if>
<if test="openId!=null">open_id=#{openId},</if>
<if test="nickName!=null">nick_name=#{nickName},</if>
<if test="sex!=null">sex=#{sex},</if>
<if test="groupid!=null">groupid=#{groupid},</if>
<if test="language!=null">language=#{language},</if>
<if test="remark!=null">remark=#{remark},</if>
<if test="province!=null">province=#{province},</if>
<if test="headImgUrl!=null">head_img_url=#{headImgUrl},</if>
<if test="wechatInfoId!=null">wechat_info_id=#{wechatInfoId},</if>
<if test="id!=null">id=#{id},</if>
<if test="status!=null">status=#{status},</if>
</trim>
WHERE
id=#{id}
</update>
<update id="delete" parameterType="Long">
UPDATE
FROM wechat_user
SET
status = 0
WHERE
id=#{id}
</update>
<select id="getByOpenId" resultType="WechatUser">
select <include refid="column_list"/>
FROM wechat_user
where
status = 1
and
open_id = #{openId}
</select>
</mapper>

@ -1,16 +1,25 @@
#--------- jdbc ÅäÖÃ---------
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
jdbc.user=root
jdbc.password=mysql
#\u5B9A\u4E49\u521D\u59CB\u8FDE\u63A5\u6570
initialSize=0
#\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570
maxActive=5
#\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2
maxIdle=5
#\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2
minIdle=1
#\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4
maxWait=6000
email.port=Create property
#--------Êý¾Ý¿âÁ¬½Ó³ØÅäÖà -------
durid.pool.initialSize=5
durid.pool.maxActive=5
durid.pool.minIdle=1
durid.pool.maxWait=60000
durid.pool.timeBetweenEvictionRunsMillis=60000
durid.pool.filters=stat
durid.pool.poolPreparedStatements=false
durid.pool.maxPoolPreparedStatementPerConnectionSize=100
durid.pool.minEvictableIdleTimeMillis=300000
durid.pool.validationQuery=SELECT 'X'
durid.pool.testWhileIdle=true
durid.pool.testOnBorrow=false
durid.pool.testOnReturn=false
durid.pool.removeAbandonedTimeout=1800
durid.pool.logAbandoned=true
durid.pool.email.port=Create property

@ -13,7 +13,7 @@
<!-- 自动扫描 -->
<context:component-scan base-package="com.lq.dao" />
<context:component-scan base-package="com.lq.*.service" />
<context:component-scan base-package="com.lq.wechat.util"/>
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />
<!-- 扫描实体类,并创建表-->
<bean class="com.lq.code.executor.processor.InstantiationTracingBeanPostProcessor">

Loading…
Cancel
Save