使用binary-wang封装的工具包“判断用户是否关注公众号”

使用binary-wang封装的工具包“判断用户是否关注公众号”

//关注验证
private boolean validWatch(String openId, String appId) {
    WxMpUser wxUser = userBaseInfo(openId, appId);
    if (wxUser != null) {
        return wxUser.getSubscribe();
    }
    return false;
}
/**
 * 获取用户信息
 *
 * @param openId
 * @param appId
 * @return
 */
private WxMpUser userBaseInfo(String openId, String appId) {
    WxMpUser wxMpUser = new WxMpUser();
    try {
        WxMpService mpService = WxMpConfiguration.getMpService(appId);
        wxMpUser = mpService.getUserService().userInfo(openId);
        return wxMpUser;
    } catch (Exception e) {
        log.error("获取微信用户【】错误" + e.getMessage());
    }
    return wxMpUser;
}
@Configuration
@AllArgsConstructor
@EnableConfigurationProperties(WxMpProperties.class)
public class WxMpConfiguration {
    
    private static WxMpProperties properties ;

    @Autowired
    public void setProperties(WxMpProperties properties) {
        WxMpConfiguration.properties = properties;
    }

    private static Map<String, WxMpService> mpServices = Maps.newHashMap();
    public static Map<String, WxMpService> getMpServices() {
        return mpServices;
    }

    public static WxMpService getMpService(String appId) {
//        List<WxMpProperties.MpConfig> configs = properties.getConfigs();
//        WxMpProperties.MpConfig mpConfig = configs.get(0);
//        String appId = mpConfig.getAppId();
        return getMpServices().get(appId);
    }
@ConfigurationProperties(prefix = "wx.mp")
@Data
public class WxMpProperties {

    private List<MpConfig> configs;

    public static class MpConfig {
        /**
         * 设置微信公众号的appid
         */
        private String appId;

        /**
         * 设置微信公众号的app secret
         */
        private String secret;

        /**
         * 设置微信公众号的token
         */
        private String token;

        /**
         * 设置微信公众号的EncodingAESKey
         */
        private String aesKey;

        public String getAppId() {
            return appId;
        }

        public void setAppId(String appId) {
            this.appId = appId;
        }

        public String getSecret() {
            return secret;
        }

        public void setSecret(String secret) {
            this.secret = secret;
        }

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public String getAesKey() {
            return aesKey;
        }

        public void setAesKey(String aesKey) {
            this.aesKey = aesKey;
        }
    }

    public List<MpConfig> getConfigs() {
        return configs;
    }

    public void setConfigs(List<MpConfig> configs) {
        this.configs = configs;
    }

    @Override
    public String toString() {
        return JsonUtils.toJson(this);
    }
}
  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值