| @@ -63,6 +63,12 @@ public class WxAuthorizerInfo implements Serializable { | |||
| private String openAppid; | |||
| @io.swagger.annotations.ApiModelProperty(value="绑定开发平台时间",name="bindOpenTime") | |||
| private Date bindOpenTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="refresh_token",name="refreshToken") | |||
| private String refreshToken; | |||
| @io.swagger.annotations.ApiModelProperty(value="access_token",name="accessToken") | |||
| private String accessToken; | |||
| @io.swagger.annotations.ApiModelProperty(value="accessToken过期时间",name="accessTokenExpire") | |||
| private Date accessTokenExpire; | |||
| @@ -20,19 +20,19 @@ public class WxComponentVerifyTicket implements Serializable { | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| /**微信第三方componentAppid*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="微信第三方componentAppid",name="componentAppid") | |||
| private String componentAppid; | |||
| /**微信第三方component_verify_ticket*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="微信第三方component_verify_ticket",name="componentVerifyTicket") | |||
| private String componentVerifyTicket; | |||
| /**创建时间*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") | |||
| private Date createTime; | |||
| /**失效时间*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="失效时间",name="deadline") | |||
| private Date deadline; | |||
| @io.swagger.annotations.ApiModelProperty(value="access_token",name="accessToken") | |||
| private String accessToken; | |||
| @io.swagger.annotations.ApiModelProperty(value="access_token过期时间",name="accessTokenExpire") | |||
| private Date accessTokenExpire; | |||
| @@ -11,7 +11,11 @@ public interface WxAuthorizerInfoMapper extends CommonMapper<WxAuthorizerInfo, L | |||
| List<WxWeappInfo> findVoList(WxWeappInfo wxWeappInfo); | |||
| void updateReleaseInfo(WxAuthorizerInfo wxAuthorizerInfo); | |||
| int updateReleaseInfo(WxAuthorizerInfo wxAuthorizerInfo); | |||
| int updateRefreshToken(WxAuthorizerInfo wxAuthorizerInfo); | |||
| int updateAccessToken(WxAuthorizerInfo wxAuthorizerInfo); | |||
| @@ -7,10 +7,8 @@ import com.iformall.domain.po.WxComponentVerifyTicket; | |||
| public interface WxComponentVerifyTicketMapper extends CommonMapper<WxComponentVerifyTicket, Long> { | |||
| List<WxComponentVerifyTicket> findList(WxComponentVerifyTicket wxComponentVerifyTicket); | |||
| int updateAccessToken(WxComponentVerifyTicket wxComponentVerifyTicket); | |||
| } | |||
| @@ -24,13 +24,17 @@ | |||
| <result column="release_time" jdbcType="TIMESTAMP" property="releaseTime" /> | |||
| <result column="open_appid" jdbcType="VARCHAR" property="openAppid" /> | |||
| <result column="bind_open_time" jdbcType="TIMESTAMP" property="bindOpenTime" /> | |||
| <result column="refresh_token" jdbcType="VARCHAR" property="refreshToken" /> | |||
| <result column="access_token" jdbcType="VARCHAR" property="accessToken" /> | |||
| <result column="access_token_expire" jdbcType="TIMESTAMP" property="accessTokenExpire" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`authorizer_appid`,`head_img`,`alias`,`qrcode_url`,`create_time`,`authorization_status`,`auth_time`, | |||
| `base_status`, `base_time`, `domain_status`, `domain_time`, `webdomain_status`, `webdomain_time`, `template_status`, `template_time`, | |||
| `current_version`,`current_desc`,`release_time`, | |||
| `open_appid`,`bind_open_time` | |||
| `open_appid`,`bind_open_time`,`refresh_token`, | |||
| `access_token`,`access_token_expire` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -121,6 +125,18 @@ | |||
| where `authorizer_appid` = #{authorizerAppid} | |||
| </update> | |||
| <update id="updateRefreshToken" parameterType="com.iformall.domain.po.WxAuthorizerInfo" > | |||
| update wx_authorizer_info | |||
| set `refresh_token` = #{refreshToken} | |||
| where `authorizer_appid` = #{authorizerAppid} | |||
| </update> | |||
| <update id="updateAccessToken" parameterType="com.iformall.domain.po.WxAuthorizerInfo" > | |||
| update wx_authorizer_info | |||
| set `access_token` = #{accessToken}, `access_token_expire` = #{accessTokenExpire} | |||
| where `authorizer_appid` = #{authorizerAppid} | |||
| </update> | |||
| <resultMap id="VBaseResultMap" type="com.iformall.domain.vo.WxWeappInfo"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="authorizer_appid" jdbcType="VARCHAR" property="authorizerAppid" /> | |||
| @@ -7,6 +7,8 @@ | |||
| <result column="component_verify_ticket" jdbcType="VARCHAR" property="componentVerifyTicket" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> | |||
| <result column="deadline" jdbcType="TIMESTAMP" property="deadline" /> | |||
| <result column="access_token" jdbcType="VARCHAR" property="accessToken" /> | |||
| <result column="access_token_expire" jdbcType="TIMESTAMP" property="accessTokenExpire" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| @@ -19,7 +21,7 @@ | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != componentAppid "> | |||
| and `component_appid` like concat('%', #{componentAppid},'%') | |||
| and `component_appid` = #{componentAppid} | |||
| </if> | |||
| <if test=" null != componentVerifyTicket "> | |||
| and `component_verify_ticket` like concat('%', #{componentVerifyTicket},'%') | |||
| @@ -43,6 +45,12 @@ | |||
| select <include refid="allColumns" /> from wx_component_verify_ticket | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <update id="updateAccessToken" parameterType="com.iformall.domain.po.WxComponentVerifyTicket"> | |||
| update wx_component_verify_ticket | |||
| set `access_token` = #{accessToken}, `access_token_expire` = #{accessTokenExpire} | |||
| where component_appid = #{componentAppid} | |||
| </update> | |||
| @@ -1,14 +1,20 @@ | |||
| package com.iformall.service.wechat; | |||
| import com.iformall.domain.po.WxAuthorizerInfo; | |||
| import com.iformall.domain.po.WxComponentVerifyTicket; | |||
| import com.iformall.mapper.WxAuthorizerInfoMapper; | |||
| import com.iformall.mapper.WxComponentVerifyTicketMapper; | |||
| import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import redis.clients.jedis.Jedis; | |||
| import redis.clients.jedis.JedisPool; | |||
| import redis.clients.util.Pool; | |||
| import java.util.Date; | |||
| public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||
| private final static String COMPONENT_VERIFY_TICKET_KEY = "wechat_component_verify_ticket:"; | |||
| private final static String COMPONENT_ACCESS_TOKEN_KEY = "wechat_component_access_token:"; | |||
| @@ -30,6 +36,8 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||
| private String jsapiTicketKey; | |||
| private String cardApiTicket; | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxComponentVerifyTicketMapper wxComponentVerifyTicketMapper; | |||
| @@ -101,8 +109,14 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||
| public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { | |||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||
| jedis.setex(this.componentAccessTokenKey, expiresInSeconds - 200, componentAccessToken); | |||
| WxComponentVerifyTicket ticket = new WxComponentVerifyTicket(); | |||
| ticket.setComponentAppid(getComponentAppId()); | |||
| ticket.setAccessToken(componentAccessToken); | |||
| ticket.setAccessTokenExpire(new Date(Long.valueOf(System.currentTimeMillis() + (expiresInSeconds * 1000)))); | |||
| int num = wxComponentVerifyTicketMapper.updateAccessToken(ticket); | |||
| logger.info("updateComponentVerifyTicketAccessToken rows: " + num); | |||
| } | |||
| // TODO update to DB | |||
| } | |||
| private String getKey(String prefix, String appId) { | |||
| @@ -121,8 +135,12 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||
| jedis.set(this.getKey(this.authorizerRefreshTokenKey, appId), authorizerRefreshToken); | |||
| WxAuthorizerInfo authorizerInfo = new WxAuthorizerInfo(); | |||
| authorizerInfo.setAuthorizerAppid(appId); | |||
| authorizerInfo.setRefreshToken(authorizerRefreshToken); | |||
| int num = wxAuthorizerInfoMapper.updateRefreshToken(authorizerInfo); | |||
| logger.info("setAuthorizerRefreshToken " + appId + " rows: " + num); | |||
| } | |||
| // TODO update to DB | |||
| } | |||
| @Override | |||
| @@ -150,6 +168,12 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||
| public void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds) { | |||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||
| jedis.setex(this.getKey(this.authorizerAccessTokenKey, appId), expiresInSeconds - 200, authorizerAccessToken); | |||
| WxAuthorizerInfo authorizerInfo = new WxAuthorizerInfo(); | |||
| authorizerInfo.setAuthorizerAppid(appId); | |||
| authorizerInfo.setAccessToken(authorizerAccessToken); | |||
| authorizerInfo.setAccessTokenExpire(new Date(Long.valueOf(System.currentTimeMillis() + (expiresInSeconds * 1000)))); | |||
| int num = wxAuthorizerInfoMapper.updateAccessToken(authorizerInfo); | |||
| logger.info("updateAuthorizerAccessToken " + appId + " rows: " + num); | |||
| } | |||
| } | |||