diff --git a/mallinkService/src/main/java/com/iformall/common/FmHttpClientBuilder.java b/mallinkService/src/main/java/com/iformall/common/FmHttpClientBuilder.java new file mode 100644 index 0000000..1ed1a3f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/common/FmHttpClientBuilder.java @@ -0,0 +1,338 @@ +package com.iformall.common; + +import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHost; +import org.apache.http.NoHttpResponseException; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.HttpRequestRetryHandler; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.config.SocketConfig; +import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.conn.DnsResolver; +import org.apache.http.conn.HttpClientConnectionManager; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.protocol.HttpContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * httpclient 连接管理器 自带DNS解析. + *

大部分代码拷贝自:DefaultApacheHttpClientBuilder

+ * + * @author Andy.Huo + */ +public class FmHttpClientBuilder implements ApacheHttpClientBuilder { + protected final Logger log = LoggerFactory.getLogger(FmHttpClientBuilder.class); + private final AtomicBoolean prepared = new AtomicBoolean(false); + private int connectionRequestTimeout = 3000; + private int connectionTimeout = 5000; + private int soTimeout = 5000; + private int idleConnTimeout = 60000; + private int checkWaitTime = 60000; + private int maxConnPerHost = 10; + private int maxTotalConn = 50; + private String userAgent; + + private DnsResolver dnsResover; + + private HttpRequestRetryHandler httpRequestRetryHandler = new HttpRequestRetryHandler() { + @Override + public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { + if (executionCount > 3) { + log.warn("Maximum tries reached for client http pool "); + return false; + } + if (exception instanceof NoHttpResponseException) { // NoHttpResponseException 重试 + log.warn("NoHttpResponseException on " + executionCount + " call"); + return true; + } + if (exception instanceof ConnectTimeoutException) { // 连接超时重试 + log.warn("ConnectTimeoutException on " + executionCount + " call"); + return true; + } + //if (exception instanceof SocketTimeoutException) { //响应超时不重试,避免造成业务数据不一致 + // log.warn("SocketTimeoutException on " + executionCount + " call"); + //} + return false; + } + }; + private SSLConnectionSocketFactory sslConnectionSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); + private PlainConnectionSocketFactory plainConnectionSocketFactory = PlainConnectionSocketFactory.getSocketFactory(); + private String httpProxyHost; + private int httpProxyPort; + private String httpProxyUsername; + private String httpProxyPassword; + + /** + * 闲置连接监控线程. + */ + private IdleConnectionMonitorThread idleConnectionMonitorThread; + private HttpClientBuilder httpClientBuilder; + + private FmHttpClientBuilder() { + } + + public static FmHttpClientBuilder get() { + return new FmHttpClientBuilder(); + } + + @Override + public ApacheHttpClientBuilder httpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; + return this; + } + + @Override + public ApacheHttpClientBuilder httpProxyPort(int httpProxyPort) { + this.httpProxyPort = httpProxyPort; + return this; + } + + @Override + public ApacheHttpClientBuilder httpProxyUsername(String httpProxyUsername) { + this.httpProxyUsername = httpProxyUsername; + return this; + } + + @Override + public ApacheHttpClientBuilder httpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; + return this; + } + + @Override + public ApacheHttpClientBuilder sslConnectionSocketFactory(SSLConnectionSocketFactory sslConnectionSocketFactory) { + this.sslConnectionSocketFactory = sslConnectionSocketFactory; + return this; + } + + /** + * 获取链接的超时时间设置,默认3000ms + *

+ * 设置为零时不超时,一直等待. 设置为负数是使用系统默认设置(非上述的3000ms的默认值,而是httpclient的默认设置). + *

+ * + * @param connectionRequestTimeout 获取链接的超时时间设置(单位毫秒),默认3000ms + */ + public void setConnectionRequestTimeout(int connectionRequestTimeout) { + this.connectionRequestTimeout = connectionRequestTimeout; + } + + /** + * 建立链接的超时时间,默认为5000ms.由于是在链接池获取链接,此设置应该并不起什么作用 + *

+ * 设置为零时不超时,一直等待. 设置为负数是使用系统默认设置(非上述的5000ms的默认值,而是httpclient的默认设置). + *

+ * + * @param connectionTimeout 建立链接的超时时间设置(单位毫秒),默认5000ms + */ + public void setConnectionTimeout(int connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + /** + * 默认NIO的socket超时设置,默认5000ms. + * + * @param soTimeout 默认NIO的socket超时设置,默认5000ms. + * @see java.net.SocketOptions#SO_TIMEOUT + */ + public void setSoTimeout(int soTimeout) { + this.soTimeout = soTimeout; + } + + /** + * 空闲链接的超时时间,默认60000ms. + *

+ * 超时的链接将在下一次空闲链接检查是被销毁 + *

+ * + * @param idleConnTimeout 空闲链接的超时时间,默认60000ms. + */ + public void setIdleConnTimeout(int idleConnTimeout) { + this.idleConnTimeout = idleConnTimeout; + } + + /** + * 检查空间链接的间隔周期,默认60000ms. + * + * @param checkWaitTime 检查空间链接的间隔周期,默认60000ms. + */ + public void setCheckWaitTime(int checkWaitTime) { + this.checkWaitTime = checkWaitTime; + } + + /** + * 每路的最大链接数,默认10. + * + * @param maxConnPerHost 每路的最大链接数,默认10 + */ + public void setMaxConnPerHost(int maxConnPerHost) { + this.maxConnPerHost = maxConnPerHost; + } + + /** + * 最大总连接数,默认50. + * + * @param maxTotalConn 最大总连接数,默认50 + */ + public void setMaxTotalConn(int maxTotalConn) { + this.maxTotalConn = maxTotalConn; + } + + /** + * 自定义httpclient的User Agent. + * + * @param userAgent User Agent + */ + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public IdleConnectionMonitorThread getIdleConnectionMonitorThread() { + return this.idleConnectionMonitorThread; + } + + private synchronized void prepare() { + if (prepared.get()) { + return; + } + + Registry registry = + RegistryBuilder.create() + .register("http", this.plainConnectionSocketFactory) + .register("https", this.sslConnectionSocketFactory) + .build(); + + @SuppressWarnings("resource") + PoolingHttpClientConnectionManager connectionManager; + if (dnsResover != null) { + if (log.isDebugEnabled()) { + log.debug("specified dns resolver."); + } + connectionManager = new PoolingHttpClientConnectionManager(registry, dnsResover); + } else { + if (log.isDebugEnabled()) { + log.debug("Not specified dns resolver."); + } + connectionManager = new PoolingHttpClientConnectionManager(registry); + } + + connectionManager.setMaxTotal(this.maxTotalConn); + connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost); + connectionManager + .setDefaultSocketConfig(SocketConfig.copy(SocketConfig.DEFAULT).setSoTimeout(this.soTimeout).build()); + + this.idleConnectionMonitorThread = new IdleConnectionMonitorThread( + connectionManager, this.idleConnTimeout, this.checkWaitTime); + this.idleConnectionMonitorThread.setDaemon(true); + this.idleConnectionMonitorThread.start(); + + this.httpClientBuilder = HttpClients.custom().setConnectionManager(connectionManager) + .setConnectionManagerShared(true) + .setDefaultRequestConfig( + RequestConfig.custom() + .setSocketTimeout(this.soTimeout) + .setConnectTimeout(this.connectionTimeout) + .setConnectionRequestTimeout(this.connectionRequestTimeout) + .build()) + .setRetryHandler(this.httpRequestRetryHandler); + + if (StringUtils.isNotBlank(this.httpProxyHost) && StringUtils.isNotBlank(this.httpProxyUsername)) { + // 使用代理服务器 需要用户认证的代理服务器 + CredentialsProvider provider = new BasicCredentialsProvider(); + provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort), + new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword)); + this.httpClientBuilder.setDefaultCredentialsProvider(provider); + this.httpClientBuilder.setProxy(new HttpHost(this.httpProxyHost, this.httpProxyPort)); + } + + if (StringUtils.isNotBlank(this.userAgent)) { + this.httpClientBuilder.setUserAgent(this.userAgent); + } + prepared.set(true); + } + + @Override + public CloseableHttpClient build() { + if (!prepared.get()) { + prepare(); + } + return this.httpClientBuilder.build(); + } + + public DnsResolver getDnsResover() { + return dnsResover; + } + + public void setDnsResover(DnsResolver dnsResover) { + this.dnsResover = dnsResover; + } + + public static class IdleConnectionMonitorThread extends Thread { + private final HttpClientConnectionManager connMgr; + private final int idleConnTimeout; + private final int checkWaitTime; + private volatile boolean shutdown; + + /** + * 构造方法. + */ + public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr, int idleConnTimeout, int checkWaitTime) { + super("IdleConnectionMonitorThread"); + this.connMgr = connMgr; + this.idleConnTimeout = idleConnTimeout; + this.checkWaitTime = checkWaitTime; + } + + @Override + public void run() { + try { + while (!this.shutdown) { + synchronized (this) { + wait(this.checkWaitTime); + this.connMgr.closeExpiredConnections(); + this.connMgr.closeIdleConnections(this.idleConnTimeout, TimeUnit.MILLISECONDS); + } + } + } catch (InterruptedException ignore) { + Thread.currentThread().interrupt(); + } + } + + /** + * 触发. + */ + public void trigger() { + synchronized (this) { + notifyAll(); + } + } + + /** + * 关闭. + */ + public void shutdown() { + this.shutdown = true; + synchronized (this) { + notifyAll(); + } + } + } + +} diff --git a/mlWechatOpen/src/main/java/com/iformall/config/WechatOpenProperties.java b/mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java similarity index 100% rename from mlWechatOpen/src/main/java/com/iformall/config/WechatOpenProperties.java rename to mallinkService/src/main/java/com/iformall/config/WechatOpenProperties.java diff --git a/mlWechatOpen/src/main/java/com/iformall/config/RedisProperies.java b/mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java similarity index 97% rename from mlWechatOpen/src/main/java/com/iformall/config/RedisProperies.java rename to mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java index 21602ae..1a84a34 100644 --- a/mlWechatOpen/src/main/java/com/iformall/config/RedisProperies.java +++ b/mallinkService/src/main/java/com/iformall/config/WechatRedisProperies.java @@ -12,7 +12,7 @@ import javax.net.ssl.SSLSocketFactory; * Stormeye */ @ConfigurationProperties(prefix = "wechat.redis") -public class RedisProperies extends JedisPoolConfig { +public class WechatRedisProperies extends JedisPoolConfig { private String host = Protocol.DEFAULT_HOST; private int port = Protocol.DEFAULT_PORT; private String password; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxAuthorizerInfo.java b/mallinkService/src/main/java/com/iformall/domain/po/WxAuthorizerInfo.java index a016961..01a03e8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxAuthorizerInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxAuthorizerInfo.java @@ -21,6 +21,10 @@ public class WxAuthorizerInfo implements Serializable { @Transient protected String sortColumns; + @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") + private String tenantId; + @io.swagger.annotations.ApiModelProperty(value="1B端2C端",name="type") + private Integer type; @io.swagger.annotations.ApiModelProperty(value="授权方appid",name="authorizerAppid") private String authorizerAppid; @io.swagger.annotations.ApiModelProperty(value="授权方头像",name="headImg") @@ -75,6 +79,7 @@ public class WxAuthorizerInfo implements Serializable { public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") + ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") ,AuthorizerAppid_ASC("`authorizer_appid` ASC"),AuthorizerAppid_DESC("`authorizer_appid` DESC") ,HeadImg_ASC("`head_img` ASC"),HeadImg_DESC("`head_img` DESC") ,Alias_ASC("`alias` ASC"),Alias_DESC("`alias` DESC") @@ -96,6 +101,7 @@ public class WxAuthorizerInfo implements Serializable { ,ReleaseTime_ASC("`release_time` ASC"),ReleaseTime_DESC("`release_time` DESC") ,OpenAppId_ASC("`open_appid` ASC"),OpenAppId_DESC("`open_appid` DESC") ,BindOpenTime_ASC("`bind_open_time` ASC"),BindOpen_DESC("`bind_open_time` DESC") + ,Type_ASC("`type` ASC"),Type_DESC("`type` DESC") ; private String value; Field(String value){ diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java index 5d8f057..04471c0 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCUser.java @@ -157,6 +157,9 @@ public class WxCUser implements Serializable { private Date subsSubscribeTime; @io.swagger.annotations.ApiModelProperty(value="关注订阅号Scene",name="subsSubscribeScene") private String subsSubscribeScene; + /**积分**/ + @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") + private Integer credit; //渠道名称 @@ -488,7 +491,15 @@ public class WxCUser implements Serializable { this.subsSubscribeScene = subsSubscribeScene; } - public static enum Field + public Integer getCredit() { + return credit; + } + + public void setCredit(Integer credit) { + this.credit = credit; + } + + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") @@ -520,7 +531,9 @@ public class WxCUser implements Serializable { ,LoginCount_ASC("`login_count` ASC"),LoginCount_DESC("`login_count` DESC") ,ExtraInfo_ASC("`extra_info` ASC"),ExtraInfo_DESC("`extra_info` DESC") ,IsSubscribe_ASC("`is_subscribe` ASC"),IsSubscribe_DESC("`is_subscribe` DESC") - ; + ,Credit_ASC("`credit` ASC"),Credit_DESC("`credit` DESC") + + ; private String value; Field(String value){ this.value = value; @@ -575,12 +588,12 @@ public class WxCUser implements Serializable { } public String createToken(Date currentDate) { - if (expireTime == null || expireTime.getTime() < currentDate.getTime()) + if (expireTime == null || expireTime.getTime() - Constant.H_EXPIRE < currentDate.getTime()) { //生成一个token this.token = UUID.randomUUID().toString(); //过期时间 - this.expireTime = new Date(currentDate.getTime() + Constant.EXPIRE * 1000); + this.expireTime = new Date(currentDate.getTime() + Constant.EXPIRE); } return this.token; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxWeappInfo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxWeappInfo.java index c277b12..1be27ae 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxWeappInfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxWeappInfo.java @@ -11,16 +11,14 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) public class WxWeappInfo extends WxAuthorizerInfo { - @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") - private String tenantId; - @io.swagger.annotations.ApiModelProperty(value="小程序类型(1-B端 2-C端 3-服务号 4-订阅号)",name="type") - private Integer type; @io.swagger.annotations.ApiModelProperty(value="小程序名称",name="name") private String name; public static enum Field { Id_ASC("ai.`id` ASC"),Id_DESC("ai.`id` DESC") + ,TenantID_ASC("ai.`tenant_id` ASC"),TenantID_DESC("ai.`tenant_id` DESC") + ,Type_ASC("ai.`type` ASC"),Type_DESC("ai.`type` DESC") ,AuthorizerAppid_ASC("ai.`authorizer_appid` ASC"),AuthorizerAppid_DESC("ai.`authorizer_appid` DESC") ,HeadImg_ASC("ai.`head_img` ASC"),HeadImg_DESC("ai.`head_img` DESC") ,Alias_ASC("ai.`alias` ASC"),Alias_DESC("ai.`alias` DESC") @@ -43,8 +41,6 @@ public class WxWeappInfo extends WxAuthorizerInfo { ,OpenAppid_ASC("ai.`open_appid` ASC"),OpenAppid_DESC("ai.`open_appid` DESC") ,BindOpenTime_ASC("ai.`bind_open_time` ASC"),BindOpenTime_DESC("ai.`bind_open_time` DESC") ,Name_ASC("a.`name` ASC"),Name_DESC("a.`name` DESC") - ,TenantID_ASC("a.`tenant_id` ASC"),TenantID_DESC("a.`tenant_id` DESC") - ,Type_ASC("a.`type` ASC"),Type_DESC("a.`type` DESC") ; private String value; Field(String value){ diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java index 51df519..022a2ae 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxAuthorizerInfoMapper.java @@ -9,11 +9,9 @@ public interface WxAuthorizerInfoMapper extends CommonMapper findList(WxAuthorizerInfo wxAuthorizerInfo); - List findWeappList(); - - List findWxMpList(); + WxAuthorizerInfo findMp(WxAuthorizerInfo wxAuthorizerInfo); - List findVoList(WxWeappInfo wxWeappInfo); + WxAuthorizerInfo findWeChatMp(WxAuthorizerInfo wxAuthorizerInfo); WxWeappInfo findVo(WxWeappInfo wxWeappInfo); @@ -22,10 +20,13 @@ public interface WxAuthorizerInfoMapper extends CommonMapper findWeappList(); + + List findWxMpList(); + + List findVoList(WxWeappInfo wxWeappInfo); + + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCUserMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCUserMapper.java index 3f35587..ff4f073 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCUserMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCUserMapper.java @@ -1,7 +1,10 @@ package com.iformall.mapper; +import java.util.HashMap; import java.util.List; +import org.apache.ibatis.annotations.Param; + import com.iformall.common.CommonMapper; import com.iformall.domain.dto.WxCUserBasicInfoDto; import com.iformall.domain.po.WxCUser; diff --git a/mallinkService/src/main/java/com/iformall/service/WxCUserService.java b/mallinkService/src/main/java/com/iformall/service/WxCUserService.java index 5e2840f..26e99b4 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCUserService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCUserService.java @@ -2,7 +2,9 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; import com.iformall.domain.dto.WxCUserBasicInfoDto; +import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.domain.po.WxCUser; +import me.chanjar.weixin.mp.bean.result.WxMpUser; public interface WxCUserService { @@ -33,12 +35,12 @@ public interface WxCUserService { WxCUser getByOpenId(WxCUser record); /** - * 根据openId获得实体 + * 根据object获得实体 * * @param record * @return */ - WxCUser getByWxOpenId(WxCUser record); + WxCUser getByObject(WxCUser record); /** * 保存或更新实体 @@ -48,6 +50,16 @@ public interface WxCUserService { int saveOrUpdate(WxCUser record); /** + + * 保存或更新实体 + * + * @param mpUser + * @param authorizerInfo + */ + int saveOrUpdateMpUser(WxMpUser mpUser, WxAuthorizerInfo authorizerInfo); + + /** +>>>>>>> refs/tags/jenkins-back_end_wechat-98 * 根据Id删除实体 * * @param id diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserServiceImpl.java index 800ebb0..2a63e9f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCUserServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCUserServiceImpl.java @@ -4,9 +4,12 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.IdWorker; import com.iformall.domain.dto.WxCUserBasicInfoDto; +import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.domain.po.WxCUser; +import com.iformall.enums.EnumAppType; import com.iformall.mapper.WxCUserMapper; import com.iformall.service.WxCUserService; +import me.chanjar.weixin.mp.bean.result.WxMpUser; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,8 +41,13 @@ public class WxCUserServiceImpl implements WxCUserService { } @Override - public WxCUser getByWxOpenId(WxCUser record) { - return wxCUserMapper.selectOne(record); + public WxCUser getByObject(WxCUser record) { + try { + return wxCUserMapper.selectOne(record); + } catch (Exception e) { + logger.error("NOT found: " + e.getMessage()); + } + return null; } @Override @@ -72,6 +80,66 @@ public class WxCUserServiceImpl implements WxCUserService { return ret; } + @Override + public int saveOrUpdateMpUser(WxMpUser mpUser, WxAuthorizerInfo authorizerInfo) { + // 1. check user exist + WxCUser userQ = new WxCUser(); + userQ.setTenantId(authorizerInfo.getTenantId()); + boolean bHaveUnionId = false; + if(StringUtils.isNotBlank(mpUser.getUnionId())) { + userQ.setUnionId(mpUser.getUnionId()); + bHaveUnionId = true; + } else { + userQ.setOpenAppId(authorizerInfo.getOpenAppid()); + if(authorizerInfo.getType().equals(EnumAppType.MP_S.getCode())) { + userQ.setMpOpenId(mpUser.getOpenId()); + userQ.setMpAppId(authorizerInfo.getAuthorizerAppid()); + } else if(authorizerInfo.getType().equals(EnumAppType.MP_P.getCode())) { + userQ.setSubsOpenId(mpUser.getOpenId()); + userQ.setSubsAppId(authorizerInfo.getAuthorizerAppid()); + } + } + WxCUser oldUser = getByObject(userQ); + boolean bHave = false; + if(oldUser != null) { + userQ.setId(oldUser.getId()); + bHave = true; + } + if(!bHave && !mpUser.getSubscribe()) { + // 未找到,且是关注消息, 直接返回 + return 0; + } + if(bHaveUnionId) { + userQ.setOpenAppId(authorizerInfo.getOpenAppid()); + if (authorizerInfo.getType().equals(EnumAppType.MP_S.getCode())) { + userQ.setMpOpenId(mpUser.getOpenId()); + userQ.setMpAppId(authorizerInfo.getAuthorizerAppid()); + } else if (authorizerInfo.getType().equals(EnumAppType.MP_P.getCode())) { + userQ.setSubsOpenId(mpUser.getOpenId()); + userQ.setSubsAppId(authorizerInfo.getAuthorizerAppid()); + } + } + if(((oldUser != null && StringUtils.isBlank(oldUser.getNickName())) || (oldUser == null)) + && StringUtils.isNotBlank(mpUser.getNickname())) { + userQ.setNickName(mpUser.getNickname()); + userQ.setGender(mpUser.getSex()); + userQ.setAvatarUrl(mpUser.getHeadImgUrl()); + userQ.setCity(mpUser.getCity()); + userQ.setProvince(mpUser.getProvince()); + userQ.setLanguage(mpUser.getLanguage()); + } + if(authorizerInfo.getType().equals(EnumAppType.MP_S.getCode())) { + userQ.setMpSubscribe(mpUser.getSubscribe()?1:0); + userQ.setMpSubscribeScene(mpUser.getSubscribeScene()); + userQ.setMpSubscribeTime(new Date(mpUser.getSubscribeTime())); + } else if(authorizerInfo.getType().equals(EnumAppType.MP_P.getCode())) { + userQ.setSubsSubscribe(mpUser.getSubscribe()?1:0); + userQ.setSubsSubscribeScene(mpUser.getSubscribeScene()); + userQ.setMpSubscribeTime(new Date(mpUser.getSubscribeTime())); + } + return saveOrUpdate(userQ); + } + @Override public void deleteById(Long id) { wxCUserMapper.deleteByPrimaryKey(id); diff --git a/mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenInRedisDBConfigStorage.java b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java similarity index 94% rename from mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenInRedisDBConfigStorage.java rename to mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java index f14fe36..eb5228c 100644 --- a/mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenInRedisDBConfigStorage.java +++ b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenInRedisDBConfigStorage.java @@ -1,23 +1,23 @@ package com.iformall.service.wechat; +import com.iformall.common.FmHttpClientBuilder; 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.common.util.http.apache.ApacheHttpClientBuilder; import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage; import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.util.Pool; import java.util.Date; -public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { +public class FmOpenInRedisDBConfigStorage 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:"; @@ -45,16 +45,16 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public WxOpenInRedisDBConfigStorage(Pool jedisPool) { + public FmOpenInRedisDBConfigStorage(Pool jedisPool) { this.jedisPool = jedisPool; } - public WxOpenInRedisDBConfigStorage(Pool jedisPool, String keyPrefix) { + public FmOpenInRedisDBConfigStorage(Pool jedisPool, String keyPrefix) { this.jedisPool = jedisPool; this.keyPrefix = keyPrefix; } - public WxOpenInRedisDBConfigStorage(JedisPool jedisPool, WxComponentVerifyTicketMapper componentVerifyTicketMapper, WxAuthorizerInfoMapper authorizerInfoMapper) { + public FmOpenInRedisDBConfigStorage(JedisPool jedisPool, WxComponentVerifyTicketMapper componentVerifyTicketMapper, WxAuthorizerInfoMapper authorizerInfoMapper) { this.jedisPool = jedisPool; this.wxComponentVerifyTicketMapper = componentVerifyTicketMapper; this.wxAuthorizerInfoMapper = authorizerInfoMapper; @@ -245,4 +245,9 @@ public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { // TODO update to DB } + + @Override + public ApacheHttpClientBuilder getApacheHttpClientBuilder() { + return FmHttpClientBuilder.get(); + } } diff --git a/mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenService.java b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java similarity index 88% rename from mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenService.java rename to mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java index 36aea95..b2f954f 100644 --- a/mlWechatOpen/src/main/java/com/iformall/service/wechat/WxOpenService.java +++ b/mallinkService/src/main/java/com/iformall/service/wechat/FmOpenService.java @@ -1,6 +1,6 @@ package com.iformall.service.wechat; -import com.iformall.config.RedisProperies; +import com.iformall.config.WechatRedisProperies; import com.iformall.config.WechatOpenProperties; import com.iformall.mapper.WxAuthorizerInfoMapper; import com.iformall.mapper.WxComponentVerifyTicketMapper; @@ -19,13 +19,13 @@ import javax.annotation.PostConstruct; * Stormeye WU */ @Service -@EnableConfigurationProperties({WechatOpenProperties.class, RedisProperies.class}) -public class WxOpenService extends WxOpenServiceImpl { +@EnableConfigurationProperties({WechatOpenProperties.class, WechatRedisProperies.class}) +public class FmOpenService extends WxOpenServiceImpl { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private WechatOpenProperties wechatProperties; @Autowired - private RedisProperies redisProperies; + private WechatRedisProperies redisProperies; @Autowired private WxComponentVerifyTicketMapper componentVerifyTicketMapper; @@ -38,7 +38,7 @@ public class WxOpenService extends WxOpenServiceImpl { @PostConstruct public void init() { - WxOpenInRedisDBConfigStorage configStorage = new WxOpenInRedisDBConfigStorage(getJedisPool(), componentVerifyTicketMapper, authorizerInfoMapper); + FmOpenInRedisDBConfigStorage configStorage = new FmOpenInRedisDBConfigStorage(getJedisPool(), componentVerifyTicketMapper, authorizerInfoMapper); configStorage.setComponentAppId(wechatProperties.getComponentAppId()); configStorage.setComponentAppSecret(wechatProperties.getComponentSecret()); configStorage.setComponentToken(wechatProperties.getComponentToken()); @@ -57,7 +57,7 @@ public class WxOpenService extends WxOpenServiceImpl { private JedisPool getJedisPool() { if (pool == null) { - synchronized (WxOpenService.class) { + synchronized (FmOpenService.class) { if (pool == null) { pool = new JedisPool(redisProperies, redisProperies.getHost(), redisProperies.getPort(), redisProperies.getConnectionTimeout(), diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index d5fb7b8..42f7d2e 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -3,10 +3,10 @@ package com.iformall.utils; public class Constant { // 1小时过期, - public final static int C_EXPIRE = 3600000; + public final static int H_EXPIRE = 3600000; // TOKEN过期时间, 24小时后过期 - public final static int EXPIRE = 3600 * 24; + public final static int EXPIRE = H_EXPIRE * 24; // C端token public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; diff --git a/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml index 2d49138..e5b181b 100644 --- a/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAuthorizerInfoMapper.xml @@ -3,6 +3,8 @@ + + @@ -30,7 +32,7 @@ - `id`,`authorizer_appid`,`head_img`,`alias`,`qrcode_url`,`create_time`,`authorization_status`,`auth_time`, + `id`,`tenant_id`,`type`,`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`,`refresh_token`, @@ -42,6 +44,12 @@ and `id` = #{id} + + and `tenant_id` = #{tenantId} + + + and `type` = #{type} + and `authorizer_appid` = #{authorizerAppid} @@ -139,8 +147,25 @@ where `authorizer_appid` = #{authorizerAppid} + + + + + + @@ -162,13 +187,11 @@ - - - + - ai.`id`,ai.`authorizer_appid`,ai.`head_img`,ai.`alias`,ai.`qrcode_url`,ai.`create_time`,ai.`update_time`, + ai.`id`,ai.`tenant_id`,ai.`type`,ai.`authorizer_appid`,ai.`head_img`,ai.`alias`,ai.`qrcode_url`,ai.`create_time`,ai.`update_time`, ai.`authorization_status`,ai.`auth_time`, ai.`base_status`,ai.`base_time`, ai.`domain_status`,ai.`domain_time`, @@ -176,7 +199,7 @@ ai.`template_status`,ai.`template_time`, ai.`current_version`,ai.`current_desc`,ai.`release_time`, ai.`open_appid`,ai.`bind_open_time`, - a.`tenant_id`,a.`type`,a.`name` + a.`name` @@ -187,8 +210,11 @@ and a.`name` like concat('%', #{name},'%') + + and ai.`tenant_id` = #{tenantId} + - and a.`type` = #{type} + and ai.`type` = #{type} and ai.`authorizer_appid` = #{authorizerAppid} @@ -246,15 +272,7 @@ - - - select from wx_authorizer_info ai @@ -262,7 +280,7 @@ where a.type = 1 or a.type = 2 - select from wx_authorizer_info ai diff --git a/mallinkService/src/main/resources/mapper/WxCUserMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserMapper.xml index f2d5b54..5e7646d 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserMapper.xml @@ -43,6 +43,7 @@ + @@ -53,7 +54,7 @@ `login_count`, `extra_info`, `is_subscribe`, `open_app_id`, `mp_open_id`,`mp_app_id`,`mp_subscribe`,`mp_subscribe_time`,`mp_subscribe_scene`, - `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene` + `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene`,`credit` @@ -68,11 +69,11 @@ - and `open_id` like concat('%', #{openId},'%') + and `open_id` = #{openId} - and `union_id` like concat('%', #{unionId},'%') + and `union_id` = #{unionId} @@ -175,10 +176,6 @@ and `extra_info` = #{extraInfo} - - and `is_subscribe` = #{isSubscribe} - - and `open_app_id` = #{openAppId} @@ -199,6 +196,10 @@ and `subs_app_id` = #{subsAppId} + + and `credit` = #{credit} + + and id in diff --git a/mallinkService/src/main/resources/mapper/WxPayAccountMapper.xml b/mallinkService/src/main/resources/mapper/WxPayAccountMapper.xml index 301d78a..1bd9d5c 100644 --- a/mallinkService/src/main/resources/mapper/WxPayAccountMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxPayAccountMapper.xml @@ -4,7 +4,7 @@ - + @@ -14,7 +14,7 @@ - `id`,`mch_id`,`parent_mch_id`,`api_key`,`notify_url`,`cert_path`,`type`,`share`,`rate` + `id`,`mch_id`,`sub_mch_id`,`api_key`,`notify_url`,`cert_path`,`type`,`share`,`rate` @@ -25,11 +25,11 @@ - and `mch_id` like concat('%', #{mchId},'%') + and `mch_id` = #{mchId} - - and `parent_mch_id` like concat('%', #{parentMchId},'%') + + and `sub_mch_id` = #{subMchId} diff --git a/mlWechatOpen/pom.xml b/mlWechatOpen/pom.xml index 64c0adf..7e559a6 100644 --- a/mlWechatOpen/pom.xml +++ b/mlWechatOpen/pom.xml @@ -13,8 +13,6 @@ mlWechatOpen - 3.3.0.A - 3.3.0.A @@ -23,16 +21,6 @@ mallinkService 1.0 - - com.github.binarywang - weixin-java-open - ${weixin-java-open.version} - - - com.github.binarywang - weixin-java-mp - ${weixin-java-mp.version} - com.google.zxing core diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatAuthController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatAuthController.java index 8aeb461..e3da84e 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatAuthController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatAuthController.java @@ -3,7 +3,7 @@ package com.iformall.controller; import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.enums.EnumWxAuthorizationStatus; import com.iformall.service.WxAuthorizerInfoService; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import me.chanjar.weixin.common.error.WxErrorException; @@ -29,7 +29,7 @@ import java.util.Date; public class WechatAuthController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private WxOpenService openService; + private FmOpenService openService; @Autowired private WxAuthorizerInfoService authorizerInfoService; diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java index 4e175af..bb6f7e5 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatCalllbackController.java @@ -8,7 +8,7 @@ import com.iformall.domain.po.*; import com.iformall.enums.*; import com.iformall.mp.manager.WxMpManager; import com.iformall.service.*; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import me.chanjar.weixin.common.error.WxErrorException; @@ -45,7 +45,7 @@ public class WechatCalllbackController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired - protected WxOpenService openService; + protected FmOpenService openService; @Autowired private WxComponentVerifyTicketService componentVerifyTicketService; @@ -234,12 +234,13 @@ public class WechatCalllbackController extends BaseController { return; } - WxAppinfo appinfo = appinfoService.getByAppId(appId); + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); PrintWriter printWriter = response.getWriter(); - if(appinfo.getType().equals(EnumAppType.B.getCode()) || - appinfo.getType().equals(EnumAppType.C.getCode())) { + if(authorizerInfo != null && + (authorizerInfo.getType().equals(EnumAppType.B.getCode()) || + authorizerInfo.getType().equals(EnumAppType.C.getCode()))) { // 小程序 审核 消息 /**判断消息类型,调用对应的方法*/ switch (inMessage.getMsgType()) { diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java index 7933fc2..15e419b 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java @@ -1,6 +1,5 @@ package com.iformall.controller; -import com.alibaba.fastjson.JSON; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -11,7 +10,7 @@ import com.iformall.domain.po.*; import com.iformall.domain.vo.WxWeappCodeStatusVo; import com.iformall.enums.*; import com.iformall.service.*; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -48,7 +47,7 @@ import java.util.Map; public class WechatWeappCodeController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private WxOpenService openService; + private FmOpenService openService; @Autowired private WxWeappCodeStatusService weappCodeStatusService; @@ -439,7 +438,15 @@ public class WechatWeappCodeController { WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); WxOpenResult openRet = openMaService.releaesAudited(); logger.info(openRet.toString()); +<<<<<<< HEAD if(openRet.isSuccess()) { +======= + boolean releaseSuccess = false; + if(openRet.isSuccess()) { + releaseSuccess = true; + } + if(releaseSuccess) { +>>>>>>> refs/tags/jenkins-back_end_wechat-98 releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.SUCCESS.getCode()); } else { if(openRet.getErrcode().equalsIgnoreCase("85052")) { // app is already released diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappDraftTemplateController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappDraftTemplateController.java index 2c2a97e..6db9b9f 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappDraftTemplateController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappDraftTemplateController.java @@ -2,7 +2,7 @@ package com.iformall.controller; import com.iformall.common.Result; import com.iformall.common.ResultData; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; @@ -22,7 +22,7 @@ import java.util.List; public class WechatWeappDraftTemplateController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private WxOpenService openService; + private FmOpenService openService; @GetMapping("/tempDraftList") diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java index 36fbfe4..3aa36bf 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java @@ -8,10 +8,14 @@ import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.domain.po.WxTemplateMsg; import com.iformall.enums.EnumWxAuthorizationStatus; +import com.iformall.service.WxAppinfoService; import com.iformall.service.WxAuthorizerInfoService; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.WxTemplateMsgService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -34,11 +38,17 @@ import java.util.List; public class WechatWeappMsgTemplateController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private WxOpenService openService; + private FmOpenService openService; @Autowired private WxAuthorizerInfoService authorizerInfoService; + @Autowired + private WxAppinfoService appinfoService; + + @Autowired + private WxTemplateMsgService templateMsgService; + @ApiOperation("获取小程序模板库标题列表") @GetMapping("getTmpLibList") @ApiImplicitParams({ @@ -123,6 +133,22 @@ public class WechatWeappMsgTemplateController { @ApiOperation("删除帐号下的某个模板") @PostMapping("delTemplate") public ResultData delTemplate(@RequestParam(value = "appId") String appId, @RequestParam(value = "templateId") String templateId) { + // check app + WxAppinfo appinfo = appinfoService.getByAppId(appId); + if(appinfo == null) { + String msg = "此appId未纳入管理,请联系管理员"; + logger.error(msg); + return new ResultData(Result.ERROR, msg); + } + WxTemplateMsg msgQ = new WxTemplateMsg(); + msgQ.setTemplateId(templateId); + msgQ.setTenantId(appinfo.getTenantId()); + WxTemplateMsg msg = templateMsgService.getByObj(msgQ); + if(msg != null) { + String msgStr = "此模板正被使用,请不要删除"; + logger.error(msgStr); + return new ResultData(Result.ERROR, msgStr); + } try { WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); maService.getTemplateService().delTemplate(templateId); diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java index 7b9506a..583a48c 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java @@ -8,7 +8,7 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.enums.EnumWxAuthorizationStatus; import com.iformall.service.WxAuthorizerInfoService; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import me.chanjar.weixin.common.error.WxErrorException; @@ -33,7 +33,7 @@ import java.util.Map; public class WechatWeappSetController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired - private WxOpenService openService; + private FmOpenService openService; @Autowired private WxAuthorizerInfoService authorizerInfoService; diff --git a/mlWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java b/mlWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java index 39d492d..9e207b8 100644 --- a/mlWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java +++ b/mlWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java @@ -19,12 +19,11 @@ import com.iformall.domain.vo.WxWeappInfo; import com.iformall.domain.vo.WxWeappReleaseStatusVo; import com.iformall.enums.*; import com.iformall.service.*; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import io.swagger.models.auth.In; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.open.api.WxOpenMaService; import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; @@ -73,7 +72,7 @@ public class WxWeappInfoController extends BaseController { private WxWeappReleaseStatusService weappReleaseStatusService; @Autowired - private WxOpenService openService; + private FmOpenService openService; @Autowired private WxAppinfoService appinfoService; diff --git a/mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java b/mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java index b3a23bf..42c6020 100644 --- a/mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java +++ b/mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java @@ -1,10 +1,8 @@ package com.iformall.mp.controller; import com.iformall.common.ResultData; -import com.iformall.domain.po.WxCUser; -import com.iformall.domain.vo.WxWeappInfo; -import com.iformall.enums.EnumAppType; -import com.iformall.enums.EnumWechatSubscribe; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.mapper.WxAuthorizerInfoMapper; import com.iformall.mp.manager.WxMpManager; import com.iformall.service.WxAuthorizerInfoService; import com.iformall.service.WxCUserService; @@ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; import java.util.List; /** @@ -32,68 +29,85 @@ import java.util.List; public class WxMemController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Autowired - private WxAuthorizerInfoService authorizerInfoService; - @Autowired private WxCUserService userService; @Autowired private WxMpManager wxMpManager; + @Autowired + private WxAuthorizerInfoMapper wxAuthorizerInfoMapper; + @GetMapping("/syncAccountFansList") - public ResultData syncAccountFansList(@PathVariable String appId) throws WxErrorException { - final WxWeappInfo weappInfo = authorizerInfoService.getWeappByAppId(appId); - if(weappInfo.getType().equals(EnumAppType.MP_S.getCode()) || weappInfo.getType().equals(EnumAppType.MP_P.getCode())) { - final WxMpService wxService = wxMpManager.getMpService(appId); + public ResultData syncAccountFansList(@PathVariable String appId) { + final WxMpService wxService = wxMpManager.getMpService(appId); + + WxAuthorizerInfo authQ = new WxAuthorizerInfo(); + authQ.setAuthorizerAppid(appId); + WxAuthorizerInfo authorizerInfo = wxAuthorizerInfoMapper.findWeChatMp(authQ); - String nextOpenId = null; + String nextOpenId = null; + + while (true) { + WxMpUserList mpUserList; + try { + mpUserList = wxService.getUserService().userList(nextOpenId); + } catch (WxErrorException e) { + logger.error("获取粉丝openIds出错: " + e.getMessage()); + break; + } + logger.info(mpUserList.toString()); + getBatchUserInfos(wxService, mpUserList, authorizerInfo); + nextOpenId = mpUserList.getNextOpenid(); + if(StringUtils.isBlank(nextOpenId)) { + break; + } + } + return new ResultData(); + } + + private void getBatchUserInfos(WxMpService wxService, WxMpUserList mpUserList, WxAuthorizerInfo authorizerInfo) { + List openIds = mpUserList.getOpenids(); + + if(openIds.size() > 100) { + int index = 0; + int index_end = index + 100; while(true) { - nextOpenId = syncUsers(wxService, weappInfo, nextOpenId); - if(StringUtils.isBlank(nextOpenId)) + if(openIds.size()-1 > index_end) { + getBatchUserInfo(wxService, openIds.subList(index, index_end), authorizerInfo); + } else if(openIds.size()-1 > index) { + getBatchUserInfo(wxService, openIds.subList(index, openIds.size()-1), authorizerInfo); + } else { break; + } + index += 100; + index_end = index + 100; } + } else { + getBatchUserInfo(wxService, openIds, authorizerInfo); } - return new ResultData(); } - private String syncUsers(WxMpService wxMpService, WxWeappInfo appinfo, String nextOpenId) throws WxErrorException { - WxMpUserList mpUserList = wxMpService.getUserService().userList(nextOpenId); - logger.info(mpUserList.toString()); - if(mpUserList.getOpenids().size() <= 0){ - return mpUserList.getNextOpenid(); + private void getBatchUserInfo(WxMpService wxService, List openIds, WxAuthorizerInfo authorizerInfo) { + if(openIds.size() <= 0) { + return; + } + List userList = null; + try{ + userList = wxService.getUserService().userInfoList(openIds); + } catch (WxErrorException e) { + logger.error("batchget userinfo list error: " + e.getMessage()); + return; } - List userList = wxMpService.getUserService().userInfoList(mpUserList.getOpenids()); - logger.info(userList.toString()); - userList.stream().forEach(mpuser -> { - WxCUser user = new WxCUser(); - user.setUnionId(mpuser.getUnionId()); - user.setOpenAppId(appinfo.getOpenAppid()); - if(appinfo.getType().equals(EnumAppType.MP_S.getCode())) { - user.setMpAppId(appinfo.getAuthorizerAppid()); - user.setMpOpenId(mpuser.getOpenId()); - user.setMpSubscribe(EnumWechatSubscribe.YES.getCode()); - user.setMpSubscribeTime(new Date(mpuser.getSubscribeTime())); - user.setMpSubscribeScene(mpuser.getSubscribeScene()); - } else if(appinfo.getType().equals(EnumAppType.MP_S.getCode())) { - user.setSubsAppId(appinfo.getAuthorizerAppid()); - user.setSubsOpenId(mpuser.getOpenId()); - user.setSubsSubscribe(EnumWechatSubscribe.YES.getCode()); - user.setSubsSubscribeTime(new Date(mpuser.getSubscribeTime())); - user.setSubsSubscribeScene(mpuser.getSubscribeScene()); + if(userList != null) { + logger.info(userList.toString()); + for(WxMpUser mpUser: userList) { + try { + userService.saveOrUpdateMpUser(mpUser, authorizerInfo); + } catch (Exception e) { + logger.error("保存用户出错: " + e.getMessage()); + } } - user.setNickName(mpuser.getNickname()); - user.setGender(mpuser.getSex()); - user.setLanguage(mpuser.getLanguage()); - user.setCity(mpuser.getCity()); - user.setProvince(mpuser.getProvince()); - user.setCountryCode(mpuser.getCountry()); - user.setAvatarUrl(mpuser.getHeadImgUrl()); - user.setScene(mpuser.getQrScene()); - user.setSceneAddress(mpuser.getQrSceneStr()); - userService.saveOrUpdate(user); - - }); - return mpUserList.getNextOpenid(); + } } } diff --git a/mlWechatOpen/src/main/java/com/iformall/mp/handler/SubscribeHandler.java b/mlWechatOpen/src/main/java/com/iformall/mp/handler/SubscribeHandler.java index 541bd64..3c589af 100644 --- a/mlWechatOpen/src/main/java/com/iformall/mp/handler/SubscribeHandler.java +++ b/mlWechatOpen/src/main/java/com/iformall/mp/handler/SubscribeHandler.java @@ -1,11 +1,8 @@ package com.iformall.mp.handler; -import com.iformall.domain.po.WxCUser; -import com.iformall.domain.vo.WxWeappInfo; -import com.iformall.enums.EnumAppType; -import com.iformall.enums.EnumWechatSubscribe; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.mapper.WxAuthorizerInfoMapper; import com.iformall.mp.builder.TextBuilder; -import com.iformall.service.WxAuthorizerInfoService; import com.iformall.service.WxCUserService; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.session.WxSessionManager; @@ -26,7 +23,7 @@ import java.util.Map; public class SubscribeHandler extends AbstractHandler { @Autowired - private WxAuthorizerInfoService authorizerInfoService; + private WxAuthorizerInfoMapper wxAuthorizerInfoMapper; @Autowired private WxCUserService userService; @@ -38,39 +35,18 @@ public class SubscribeHandler extends AbstractHandler { this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser()); - WxWeappInfo weappInfo = authorizerInfoService.getWeappByAppId(weixinService.getWxMpConfigStorage().getAppId()); + String appId = weixinService.getWxMpConfigStorage().getAppId(); + WxAuthorizerInfo authQ = new WxAuthorizerInfo(); + authQ.setAuthorizerAppid(appId); + WxAuthorizerInfo authorizerInfo = wxAuthorizerInfoMapper.findWeChatMp(authQ); // 获取微信用户基本信息 try { WxMpUser userWxInfo = weixinService.getUserService() - .userInfo(wxMessage.getFromUser(), null); + .userInfo(wxMessage.getFromUser()); if (userWxInfo != null) { - WxCUser user = new WxCUser(); - user.setUnionId(userWxInfo.getUnionId()); - user.setOpenAppId(weappInfo.getOpenAppid()); - if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - user.setMpAppId(weappInfo.getAuthorizerAppid()); - user.setMpOpenId(userWxInfo.getOpenId()); - user.setMpSubscribe(EnumWechatSubscribe.YES.getCode()); - user.setMpSubscribeTime(new Date(userWxInfo.getSubscribeTime())); - user.setMpSubscribeScene(userWxInfo.getSubscribeScene()); - } else if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - user.setSubsAppId(weappInfo.getAuthorizerAppid()); - user.setSubsOpenId(userWxInfo.getOpenId()); - user.setSubsSubscribe(EnumWechatSubscribe.YES.getCode()); - user.setSubsSubscribeTime(new Date(userWxInfo.getSubscribeTime())); - user.setSubsSubscribeScene(userWxInfo.getSubscribeScene()); - } - user.setNickName(userWxInfo.getNickname()); - user.setGender(userWxInfo.getSex()); - user.setLanguage(userWxInfo.getLanguage()); - user.setCity(userWxInfo.getCity()); - user.setProvince(userWxInfo.getProvince()); - user.setCountryCode(userWxInfo.getCountry()); - user.setAvatarUrl(userWxInfo.getHeadImgUrl()); - user.setScene(userWxInfo.getQrScene()); - user.setSceneAddress(userWxInfo.getQrSceneStr()); - userService.saveOrUpdate(user); + this.logger.info(userWxInfo.toString()); + userService.saveOrUpdateMpUser(userWxInfo, authorizerInfo); } } catch (WxErrorException e) { if (e.getError().getErrorCode() == 48001) { diff --git a/mlWechatOpen/src/main/java/com/iformall/mp/handler/UnsubscribeHandler.java b/mlWechatOpen/src/main/java/com/iformall/mp/handler/UnsubscribeHandler.java index 436706c..cffa85a 100644 --- a/mlWechatOpen/src/main/java/com/iformall/mp/handler/UnsubscribeHandler.java +++ b/mlWechatOpen/src/main/java/com/iformall/mp/handler/UnsubscribeHandler.java @@ -1,15 +1,13 @@ package com.iformall.mp.handler; -import com.iformall.domain.po.WxCUser; -import com.iformall.domain.vo.WxWeappInfo; -import com.iformall.enums.EnumAppType; -import com.iformall.enums.EnumWechatSubscribe; -import com.iformall.service.WxAuthorizerInfoService; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.mapper.WxAuthorizerInfoMapper; import com.iformall.service.WxCUserService; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.mp.bean.result.WxMpUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,9 +20,8 @@ import java.util.Map; @Component public class UnsubscribeHandler extends AbstractHandler { - @Autowired - private WxAuthorizerInfoService authorizerInfoService; + private WxAuthorizerInfoMapper wxAuthorizerInfoMapper; @Autowired private WxCUserService userService; @@ -36,32 +33,18 @@ public class UnsubscribeHandler extends AbstractHandler { String openId = wxMessage.getFromUser(); this.logger.info("取消关注用户 OPENID: " + openId); - WxWeappInfo weappInfo = authorizerInfoService.getWeappByAppId(wxMpService.getWxMpConfigStorage().getAppId()); - try { - WxCUser userQ = new WxCUser(); - userQ.setOpenAppId(weappInfo.getOpenAppid()); - if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - userQ.setMpAppId(weappInfo.getAuthorizerAppid()); - userQ.setMpOpenId(openId); - } else if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - userQ.setSubsAppId(weappInfo.getAuthorizerAppid()); - userQ.setSubsOpenId(openId); - } - WxCUser oldUser = userService.getByWxOpenId(userQ); - if(oldUser != null) { - userQ.setId(oldUser.getId()); - if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - userQ.setMpSubscribe(EnumWechatSubscribe.NO.getCode()); - userQ.setMpSubscribeTime(new Date(wxMessage.getCreateTime())); - } else if(weappInfo.getType().equals(EnumAppType.MP_S.getCode())) { - userQ.setSubsSubscribe(EnumWechatSubscribe.NO.getCode()); - userQ.setSubsSubscribeTime(new Date(wxMessage.getCreateTime())); - } - userService.saveOrUpdate(userQ); - } - } catch (Exception e) { - this.logger.error(e.getMessage()); - } + String appId = wxMpService.getWxMpConfigStorage().getAppId(); + WxAuthorizerInfo authQ = new WxAuthorizerInfo(); + authQ.setAuthorizerAppid(appId); + WxAuthorizerInfo authorizerInfo = wxAuthorizerInfoMapper.findWeChatMp(authQ); + + WxMpUser mpUser = new WxMpUser(); + mpUser.setOpenId(wxMessage.getFromUser()); + mpUser.setSubscribe(false); + mpUser.setSubscribeTime(wxMessage.getCreateTime()); + + userService.saveOrUpdateMpUser(mpUser, authorizerInfo); + return null; } diff --git a/mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java b/mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java index 110562b..e8d8f9d 100644 --- a/mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java +++ b/mlWechatOpen/src/main/java/com/iformall/mp/manager/WxMpManager.java @@ -2,7 +2,7 @@ package com.iformall.mp.manager; import com.iformall.mp.handler.*; import com.iformall.service.WxAppinfoService; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import me.chanjar.weixin.mp.api.WxMpMessageRouter; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.constant.WxMpEventConstants; @@ -21,7 +21,7 @@ public class WxMpManager { @Autowired - protected WxOpenService openService; + protected FmOpenService openService; @Autowired private WxAppinfoService appinfoService; diff --git a/mlWechatOpen/src/main/java/com/iformall/schedule/AppAccessTokenSchedule.java b/mlWechatOpen/src/main/java/com/iformall/schedule/AppAccessTokenSchedule.java index 915d319..eeb51fc 100644 --- a/mlWechatOpen/src/main/java/com/iformall/schedule/AppAccessTokenSchedule.java +++ b/mlWechatOpen/src/main/java/com/iformall/schedule/AppAccessTokenSchedule.java @@ -2,7 +2,7 @@ package com.iformall.schedule; import com.iformall.domain.vo.WxWeappInfo; import com.iformall.mapper.WxAuthorizerInfoMapper; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import me.chanjar.weixin.common.error.WxErrorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,11 +20,13 @@ public class AppAccessTokenSchedule { private WxAuthorizerInfoMapper authorizerInfoMapper; @Autowired - private WxOpenService openService; + private FmOpenService openService; - //@Scheduled(cron = "0 0 0/1 * * *?") // 每小时更新一次 - @Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 + // @Scheduled(cron = "0 40 */1 * * *?") // 每小时更新一次 + //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 public void updateAppAccessToken() { + // 暂不启用定时token设置 + /* // 微信小程序 List weappList = authorizerInfoMapper.findWeappList(); weappList.stream().forEach(weappInfo -> { @@ -44,6 +46,7 @@ public class AppAccessTokenSchedule { logger.error(e.getMessage()); } }); + */ } } \ No newline at end of file diff --git a/mlWechatOpen/src/main/java/com/iformall/schedule/UserUnionIdSchedule.java b/mlWechatOpen/src/main/java/com/iformall/schedule/UserUnionIdSchedule.java index f7e4a6b..836eb3b 100644 --- a/mlWechatOpen/src/main/java/com/iformall/schedule/UserUnionIdSchedule.java +++ b/mlWechatOpen/src/main/java/com/iformall/schedule/UserUnionIdSchedule.java @@ -11,7 +11,7 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.WxPayAccountMapper; import com.iformall.mapper.WxPayOrderMapper; import com.iformall.service.WxAppinfoService; -import com.iformall.service.wechat.WxOpenService; +import com.iformall.service.wechat.FmOpenService; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.open.api.WxOpenMaService; import org.apache.commons.lang3.StringUtils; @@ -39,9 +39,7 @@ public class UserUnionIdSchedule { @Autowired private WxPayAccountMapper payAccountMapper; - @Autowired - private WxOpenService openService; - + private FmOpenService openService; @Autowired WxAppinfoService wxAppinfoService; @@ -92,6 +90,7 @@ public class UserUnionIdSchedule { * 根据payOrder发送模板消息 * @param payOrderVo */ + /* public void sendUniformMessage(WxPayOrderVo payOrderVo) { if(StringUtils.isBlank(payOrderVo.getOpenId())) { return; @@ -148,4 +147,5 @@ public class UserUnionIdSchedule { throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); } } + */ } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5196022..be988f6 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ 3.3.0.A 3.3.0.A 3.3.0.A + 3.3.0.A 2.3.0 @@ -322,6 +323,12 @@ ${weixin-java-pay.version} + + com.github.binarywang + weixin-java-open + ${weixin-java-open.version} + + com.github.ulisesbocchio jasypt-spring-boot