repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/service/WxMaMultiServicesImpl.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/service/WxMaMultiServicesImpl.java
package com.binarywang.solon.wxjava.miniapp.service; import cn.binarywang.wx.miniapp.api.WxMaService; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 微信小程序 {@link WxMaMultiServices} 默认实现 * * @author monch * created on 2024/9/6 */ public class WxMaMultiServicesImpl implements WxMaMultiServices { private final Map<String, WxMaService> services = new ConcurrentHashMap<>(); @Override public WxMaService getWxMaService(String tenantId) { return this.services.get(tenantId); } /** * 根据租户 Id,添加一个 WxMaService 到列表 * * @param tenantId 租户 Id * @param wxMaService WxMaService 实例 */ public void addWxMaService(String tenantId, WxMaService wxMaService) { this.services.put(tenantId, wxMaService); } @Override public void removeWxMaService(String tenantId) { this.services.remove(tenantId); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/service/WxMaMultiServices.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/service/WxMaMultiServices.java
package com.binarywang.solon.wxjava.miniapp.service; import cn.binarywang.wx.miniapp.api.WxMaService; /** * 微信小程序 {@link WxMaService} 所有实例存放类. * * @author monch * created on 2024/9/6 */ public interface WxMaMultiServices { /** * 通过租户 Id 获取 WxMaService * * @param tenantId 租户 Id * @return WxMaService */ WxMaService getWxMaService(String tenantId); /** * 根据租户 Id,从列表中移除一个 WxMaService 实例 * * @param tenantId 租户 Id */ void removeWxMaService(String tenantId); }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/integration/WxMiniappMultiPluginImpl.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/integration/WxMiniappMultiPluginImpl.java
package com.binarywang.solon.wxjava.miniapp.integration; import com.binarywang.solon.wxjava.miniapp.configuration.services.WxMaInJedisConfiguration; import com.binarywang.solon.wxjava.miniapp.configuration.services.WxMaInMemoryConfiguration; import com.binarywang.solon.wxjava.miniapp.configuration.services.WxMaInRedissonConfiguration; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/10/9 created */ public class WxMiniappMultiPluginImpl implements Plugin { @Override public void start(AppContext context) throws Throwable { context.beanMake(WxMaMultiProperties.class); context.beanMake(WxMaInJedisConfiguration.class); context.beanMake(WxMaInMemoryConfiguration.class); context.beanMake(WxMaInRedissonConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInMemoryConfiguration.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInMemoryConfiguration.java
package com.binarywang.solon.wxjava.miniapp.configuration.services; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiProperties; import com.binarywang.solon.wxjava.miniapp.service.WxMaMultiServices; import lombok.RequiredArgsConstructor; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * 自动装配基于内存策略配置 * * @author monch * created on 2024/9/6 */ @Configuration @Condition( onProperty = "${"+WxMaMultiProperties.PREFIX + ".configStorage.type:memory} = memory" ) @RequiredArgsConstructor public class WxMaInMemoryConfiguration extends AbstractWxMaConfiguration { private final WxMaMultiProperties wxMaMultiProperties; @Bean public WxMaMultiServices wxMaMultiServices() { return this.wxMaMultiServices(wxMaMultiProperties); } @Override protected WxMaDefaultConfigImpl wxMaConfigStorage(WxMaMultiProperties wxMaMultiProperties) { return this.configInMemory(); } private WxMaDefaultConfigImpl configInMemory() { return new WxMaDefaultConfigImpl(); // return new WxMaDefaultConfigImpl(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInJedisConfiguration.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInJedisConfiguration.java
package com.binarywang.solon.wxjava.miniapp.configuration.services; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaRedisConfigImpl; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiProperties; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiRedisProperties; import com.binarywang.solon.wxjava.miniapp.service.WxMaMultiServices; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /** * 自动装配基于 jedis 策略配置 * * @author monch * created on 2024/9/6 */ @Configuration @Condition( onProperty = "${"+WxMaMultiProperties.PREFIX + ".configStorage.type} = jedis", onClass = JedisPool.class ) @RequiredArgsConstructor public class WxMaInJedisConfiguration extends AbstractWxMaConfiguration { private final WxMaMultiProperties wxMaMultiProperties; private final AppContext applicationContext; @Bean public WxMaMultiServices wxMaMultiServices() { return this.wxMaMultiServices(wxMaMultiProperties); } @Override protected WxMaDefaultConfigImpl wxMaConfigStorage(WxMaMultiProperties wxMaMultiProperties) { return this.configRedis(wxMaMultiProperties); } private WxMaDefaultConfigImpl configRedis(WxMaMultiProperties wxMaMultiProperties) { WxMaMultiRedisProperties wxMaMultiRedisProperties = wxMaMultiProperties.getConfigStorage().getRedis(); JedisPool jedisPool; if (wxMaMultiRedisProperties != null && StringUtils.isNotEmpty(wxMaMultiRedisProperties.getHost())) { jedisPool = getJedisPool(wxMaMultiProperties); } else { jedisPool = applicationContext.getBean(JedisPool.class); } return new WxMaRedisConfigImpl(jedisPool); } private JedisPool getJedisPool(WxMaMultiProperties wxMaMultiProperties) { WxMaMultiProperties.ConfigStorage storage = wxMaMultiProperties.getConfigStorage(); WxMaMultiRedisProperties redis = storage.getRedis(); JedisPoolConfig config = new JedisPoolConfig(); if (redis.getMaxActive() != null) { config.setMaxTotal(redis.getMaxActive()); } if (redis.getMaxIdle() != null) { config.setMaxIdle(redis.getMaxIdle()); } if (redis.getMaxWaitMillis() != null) { config.setMaxWaitMillis(redis.getMaxWaitMillis()); } if (redis.getMinIdle() != null) { config.setMinIdle(redis.getMinIdle()); } config.setTestOnBorrow(true); config.setTestWhileIdle(true); return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/AbstractWxMaConfiguration.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/AbstractWxMaConfiguration.java
package com.binarywang.solon.wxjava.miniapp.configuration.services; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceJoddHttpImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl; import cn.binarywang.wx.miniapp.config.WxMaConfig; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiProperties; import com.binarywang.solon.wxjava.miniapp.properties.WxMaSingleProperties; import com.binarywang.solon.wxjava.miniapp.service.WxMaMultiServices; import com.binarywang.solon.wxjava.miniapp.service.WxMaMultiServicesImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * WxMaConfigStorage 抽象配置类 * * @author monch * created on 2024/9/6 */ @RequiredArgsConstructor @Slf4j public abstract class AbstractWxMaConfiguration { protected WxMaMultiServices wxMaMultiServices(WxMaMultiProperties wxMaMultiProperties) { Map<String, WxMaSingleProperties> appsMap = wxMaMultiProperties.getApps(); if (appsMap == null || appsMap.isEmpty()) { log.warn("微信公众号应用参数未配置,通过 WxMaMultiServices#getWxMaService(\"tenantId\")获取实例将返回空"); return new WxMaMultiServicesImpl(); } /** * 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。 * * 查看 {@link cn.binarywang.wx.miniapp.config.impl.WxMaRedisConfigImpl#setAppId(String)} */ Collection<WxMaSingleProperties> apps = appsMap.values(); if (apps.size() > 1) { // 校验 appId 是否唯一 boolean multi = apps.stream() // 没有 appId,如果不判断是否为空,这里会报 NPE 异常 .collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting())) .entrySet().stream().anyMatch(e -> e.getValue() > 1); if (multi) { throw new RuntimeException("请确保微信公众号配置 appId 的唯一性"); } } WxMaMultiServicesImpl services = new WxMaMultiServicesImpl(); Set<Map.Entry<String, WxMaSingleProperties>> entries = appsMap.entrySet(); for (Map.Entry<String, WxMaSingleProperties> entry : entries) { String tenantId = entry.getKey(); WxMaSingleProperties wxMaSingleProperties = entry.getValue(); WxMaDefaultConfigImpl storage = this.wxMaConfigStorage(wxMaMultiProperties); this.configApp(storage, wxMaSingleProperties); this.configHttp(storage, wxMaMultiProperties.getConfigStorage()); WxMaService wxMaService = this.wxMaService(storage, wxMaMultiProperties); services.addWxMaService(tenantId, wxMaService); } return services; } /** * 配置 WxMaDefaultConfigImpl * * @param wxMaMultiProperties 参数 * @return WxMaDefaultConfigImpl */ protected abstract WxMaDefaultConfigImpl wxMaConfigStorage(WxMaMultiProperties wxMaMultiProperties); public WxMaService wxMaService(WxMaConfig wxMaConfig, WxMaMultiProperties wxMaMultiProperties) { WxMaMultiProperties.ConfigStorage storage = wxMaMultiProperties.getConfigStorage(); WxMaMultiProperties.HttpClientType httpClientType = storage.getHttpClientType(); WxMaService wxMaService; switch (httpClientType) { case OK_HTTP: wxMaService = new WxMaServiceOkHttpImpl(); break; case JODD_HTTP: wxMaService = new WxMaServiceJoddHttpImpl(); break; case HTTP_CLIENT: wxMaService = new WxMaServiceHttpClientImpl(); break; default: wxMaService = new WxMaServiceImpl(); break; } wxMaService.setWxMaConfig(wxMaConfig); int maxRetryTimes = storage.getMaxRetryTimes(); if (maxRetryTimes < 0) { maxRetryTimes = 0; } int retrySleepMillis = storage.getRetrySleepMillis(); if (retrySleepMillis < 0) { retrySleepMillis = 1000; } wxMaService.setRetrySleepMillis(retrySleepMillis); wxMaService.setMaxRetryTimes(maxRetryTimes); return wxMaService; } private void configApp(WxMaDefaultConfigImpl config, WxMaSingleProperties corpProperties) { String appId = corpProperties.getAppId(); String appSecret = corpProperties.getAppSecret(); String token = corpProperties.getToken(); String aesKey = corpProperties.getAesKey(); boolean useStableAccessToken = corpProperties.isUseStableAccessToken(); config.setAppid(appId); config.setSecret(appSecret); if (StringUtils.isNotBlank(token)) { config.setToken(token); } if (StringUtils.isNotBlank(aesKey)) { config.setAesKey(aesKey); } config.useStableAccessToken(useStableAccessToken); } private void configHttp(WxMaDefaultConfigImpl config, WxMaMultiProperties.ConfigStorage storage) { String httpProxyHost = storage.getHttpProxyHost(); Integer httpProxyPort = storage.getHttpProxyPort(); String httpProxyUsername = storage.getHttpProxyUsername(); String httpProxyPassword = storage.getHttpProxyPassword(); if (StringUtils.isNotBlank(httpProxyHost)) { config.setHttpProxyHost(httpProxyHost); if (httpProxyPort != null) { config.setHttpProxyPort(httpProxyPort); } if (StringUtils.isNotBlank(httpProxyUsername)) { config.setHttpProxyUsername(httpProxyUsername); } if (StringUtils.isNotBlank(httpProxyPassword)) { config.setHttpProxyPassword(httpProxyPassword); } } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInRedissonConfiguration.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/WxMaInRedissonConfiguration.java
package com.binarywang.solon.wxjava.miniapp.configuration.services; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaRedissonConfigImpl; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiProperties; import com.binarywang.solon.wxjava.miniapp.properties.WxMaMultiRedisProperties; import com.binarywang.solon.wxjava.miniapp.service.WxMaMultiServices; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.redisson.config.TransportMode; /** * 自动装配基于 redisson 策略配置 * * @author monch * created on 2024/9/6 */ @Configuration @Condition( onProperty = "${"+WxMaMultiProperties.PREFIX + ".configStorage.type} = redisson", onClass = Redisson.class ) @RequiredArgsConstructor public class WxMaInRedissonConfiguration extends AbstractWxMaConfiguration { private final WxMaMultiProperties wxMaMultiProperties; private final AppContext applicationContext; @Bean public WxMaMultiServices wxMaMultiServices() { return this.wxMaMultiServices(wxMaMultiProperties); } @Override protected WxMaDefaultConfigImpl wxMaConfigStorage(WxMaMultiProperties wxMaMultiProperties) { return this.configRedisson(wxMaMultiProperties); } private WxMaDefaultConfigImpl configRedisson(WxMaMultiProperties wxMaMultiProperties) { WxMaMultiRedisProperties redisProperties = wxMaMultiProperties.getConfigStorage().getRedis(); RedissonClient redissonClient; if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) { redissonClient = getRedissonClient(wxMaMultiProperties); } else { redissonClient = applicationContext.getBean(RedissonClient.class); } return new WxMaRedissonConfigImpl(redissonClient, wxMaMultiProperties.getConfigStorage().getKeyPrefix()); } private RedissonClient getRedissonClient(WxMaMultiProperties wxMaMultiProperties) { WxMaMultiProperties.ConfigStorage storage = wxMaMultiProperties.getConfigStorage(); WxMaMultiRedisProperties redis = storage.getRedis(); Config config = new Config(); config.useSingleServer() .setAddress("redis://" + redis.getHost() + ":" + redis.getPort()) .setDatabase(redis.getDatabase()) .setPassword(redis.getPassword()); config.setTransportMode(TransportMode.NIO); return Redisson.create(config); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaSingleProperties.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaSingleProperties.java
package com.binarywang.solon.wxjava.miniapp.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * @author monch * created on 2024/9/6 */ @Data @NoArgsConstructor public class WxMaSingleProperties implements Serializable { private static final long serialVersionUID = 1980986361098922525L; /** * 设置微信公众号的 appid. */ private String appId; /** * 设置微信公众号的 app secret. */ private String appSecret; /** * 设置微信公众号的 token. */ private String token; /** * 设置微信公众号的 EncodingAESKey. */ private String aesKey; /** * 是否使用稳定版 Access Token */ private boolean useStableAccessToken = false; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaMultiProperties.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaMultiProperties.java
package com.binarywang.solon.wxjava.miniapp.properties; import lombok.Data; import lombok.NoArgsConstructor; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * @author monch created on 2024/9/6 * @author noear */ @Data @NoArgsConstructor @Configuration @Inject("${" + WxMaMultiProperties.PREFIX + "}") public class WxMaMultiProperties implements Serializable { private static final long serialVersionUID = -5358245184407791011L; public static final String PREFIX = "wx.ma"; private Map<String, WxMaSingleProperties> apps = new HashMap<>(); /** * 自定义host配置 */ private HostConfig hosts; /** * 存储策略 */ private final ConfigStorage configStorage = new ConfigStorage(); @Data @NoArgsConstructor public static class HostConfig implements Serializable { private static final long serialVersionUID = -4172767630740346001L; /** * 对应于:https://api.weixin.qq.com */ private String apiHost; /** * 对应于:https://open.weixin.qq.com */ private String openHost; /** * 对应于:https://mp.weixin.qq.com */ private String mpHost; } @Data @NoArgsConstructor public static class ConfigStorage implements Serializable { private static final long serialVersionUID = 4815731027000065434L; /** * 存储类型. */ private StorageType type = StorageType.MEMORY; /** * 指定key前缀. */ private String keyPrefix = "wx:ma:multi"; /** * redis连接配置. */ private final WxMaMultiRedisProperties redis = new WxMaMultiRedisProperties(); /** * http客户端类型. */ private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT; /** * http代理主机. */ private String httpProxyHost; /** * http代理端口. */ private Integer httpProxyPort; /** * http代理用户名. */ private String httpProxyUsername; /** * http代理密码. */ private String httpProxyPassword; /** * http 请求最大重试次数 * <pre> * {@link cn.binarywang.wx.miniapp.api.WxMaService#setMaxRetryTimes(int)} * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)} * </pre> */ private int maxRetryTimes = 5; /** * http 请求重试间隔 * <pre> * {@link cn.binarywang.wx.miniapp.api.WxMaService#setRetrySleepMillis(int)} * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)} * </pre> */ private int retrySleepMillis = 1000; } public enum StorageType { /** * 内存 */ MEMORY, /** * jedis */ JEDIS, /** * redisson */ REDISSON, /** * redisTemplate */ REDIS_TEMPLATE } public enum HttpClientType { /** * HttpClient */ HTTP_CLIENT, /** * OkHttp */ OK_HTTP, /** * JoddHttp */ JODD_HTTP } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaMultiRedisProperties.java
solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/properties/WxMaMultiRedisProperties.java
package com.binarywang.solon.wxjava.miniapp.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * @author monch * created on 2024/9/6 */ @Data @NoArgsConstructor public class WxMaMultiRedisProperties implements Serializable { private static final long serialVersionUID = -5924815351660074401L; /** * 主机地址. */ private String host = "127.0.0.1"; /** * 端口号. */ private int port = 6379; /** * 密码. */ private String password; /** * 超时. */ private int timeout = 2000; /** * 数据库. */ private int database = 0; /** * sentinel ips */ private String sentinelIps; /** * sentinel name */ private String sentinelName; private Integer maxActive; private Integer maxIdle; private Integer maxWaitMillis; private Integer minIdle; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/test/java/features/test/LoadTest.java
solon-plugins/wx-java-qidian-solon-plugin/src/test/java/features/test/LoadTest.java
package features.test; import org.junit.jupiter.api.Test; import org.noear.solon.test.SolonTest; /** * @author noear 2024/9/4 created */ @SolonTest public class LoadTest { @Test public void load(){ } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/integration/WxQidianPluginImpl.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/integration/WxQidianPluginImpl.java
package com.binarywang.solon.wxjava.qidian.integration; import com.binarywang.solon.wxjava.qidian.config.WxQidianServiceAutoConfiguration; import com.binarywang.solon.wxjava.qidian.config.WxQidianStorageAutoConfiguration; import com.binarywang.solon.wxjava.qidian.properties.WxQidianProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/9/2 created */ public class WxQidianPluginImpl implements Plugin{ @Override public void start(AppContext context) throws Throwable { context.beanMake(WxQidianProperties.class); context.beanMake(WxQidianStorageAutoConfiguration.class); context.beanMake(WxQidianServiceAutoConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/RedisProperties.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/RedisProperties.java
package com.binarywang.solon.wxjava.qidian.properties; import lombok.Data; import java.io.Serializable; /** * redis 配置属性. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ @Data public class RedisProperties implements Serializable { private static final long serialVersionUID = -5924815351660074401L; /** * 主机地址. */ private String host = "127.0.0.1"; /** * 端口号. */ private int port = 6379; /** * 密码. */ private String password; /** * 超时. */ private int timeout = 2000; /** * 数据库. */ private int database = 0; /** * sentinel ips */ private String sentinelIps; /** * sentinel name */ private String sentinelName; private Integer maxActive; private Integer maxIdle; private Integer maxWaitMillis; private Integer minIdle; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/HostConfig.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/HostConfig.java
package com.binarywang.solon.wxjava.qidian.properties; import lombok.Data; import java.io.Serializable; @Data public class HostConfig implements Serializable { private static final long serialVersionUID = -4172767630740346001L; private String apiHost; private String openHost; private String qidianHost; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/WxQidianProperties.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/WxQidianProperties.java
package com.binarywang.solon.wxjava.qidian.properties; import com.binarywang.solon.wxjava.qidian.enums.HttpClientType; import com.binarywang.solon.wxjava.qidian.enums.StorageType; import lombok.Data; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import java.io.Serializable; import static com.binarywang.solon.wxjava.qidian.enums.StorageType.Memory; import static com.binarywang.solon.wxjava.qidian.properties.WxQidianProperties.PREFIX; /** * 企点接入相关配置属性. * * @author someone */ @Data @Configuration @Inject("${" + PREFIX + "}") public class WxQidianProperties { public static final String PREFIX = "wx.qidian"; /** * 设置腾讯企点的appid. */ private String appId; /** * 设置腾讯企点的app secret. */ private String secret; /** * 设置腾讯企点的token. */ private String token; /** * 设置腾讯企点的EncodingAESKey. */ private String aesKey; /** * 自定义host配置 */ private HostConfig hosts; /** * 存储策略 */ private ConfigStorage configStorage = new ConfigStorage(); @Data public static class ConfigStorage implements Serializable { private static final long serialVersionUID = 4815731027000065434L; /** * 存储类型. */ private StorageType type = Memory; /** * 指定key前缀. */ private String keyPrefix = "wx"; /** * redis连接配置. */ private RedisProperties redis = new RedisProperties(); /** * http客户端类型. */ private HttpClientType httpClientType = HttpClientType.HttpClient; /** * http代理主机. */ private String httpProxyHost; /** * http代理端口. */ private Integer httpProxyPort; /** * http代理用户名. */ private String httpProxyUsername; /** * http代理密码. */ private String httpProxyPassword; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/config/WxQidianStorageAutoConfiguration.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/config/WxQidianStorageAutoConfiguration.java
package com.binarywang.solon.wxjava.qidian.config; import com.binarywang.solon.wxjava.qidian.enums.StorageType; import com.binarywang.solon.wxjava.qidian.properties.RedisProperties; import com.binarywang.solon.wxjava.qidian.properties.WxQidianProperties; import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.redis.JedisWxRedisOps; import me.chanjar.weixin.common.redis.WxRedisOps; import me.chanjar.weixin.qidian.bean.WxQidianHostConfig; import me.chanjar.weixin.qidian.config.WxQidianConfigStorage; import me.chanjar.weixin.qidian.config.impl.WxQidianDefaultConfigImpl; import me.chanjar.weixin.qidian.config.impl.WxQidianRedisConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import org.noear.solon.core.AppContext; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; import redis.clients.jedis.util.Pool; import java.time.Duration; import java.util.Set; /** * 腾讯企点存储策略自动配置. * * @author alegria */ @Slf4j @Configuration @RequiredArgsConstructor public class WxQidianStorageAutoConfiguration { private final AppContext applicationContext; private final WxQidianProperties wxQidianProperties; @Inject("${wx.mp.config-storage.redis.host:") private String redisHost; @Inject("${wx.mp.configStorage.redis.host:") private String redisHost2; @Bean @Condition(onMissingBean=WxQidianConfigStorage.class) public WxQidianConfigStorage wxQidianConfigStorage() { StorageType type = wxQidianProperties.getConfigStorage().getType(); WxQidianConfigStorage config; switch (type) { case Jedis: config = jedisConfigStorage(); break; default: config = defaultConfigStorage(); break; } // wx host config if (null != wxQidianProperties.getHosts() && StringUtils.isNotEmpty(wxQidianProperties.getHosts().getApiHost())) { WxQidianHostConfig hostConfig = new WxQidianHostConfig(); hostConfig.setApiHost(wxQidianProperties.getHosts().getApiHost()); hostConfig.setQidianHost(wxQidianProperties.getHosts().getQidianHost()); hostConfig.setOpenHost(wxQidianProperties.getHosts().getOpenHost()); config.setHostConfig(hostConfig); } return config; } private WxQidianConfigStorage defaultConfigStorage() { WxQidianDefaultConfigImpl config = new WxQidianDefaultConfigImpl(); setWxMpInfo(config); return config; } private WxQidianConfigStorage jedisConfigStorage() { Pool<Jedis> jedisPool; if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) { jedisPool = getJedisPool(); } else { jedisPool = applicationContext.getBean(JedisPool.class); } WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); WxQidianRedisConfigImpl wxQidianRedisConfig = new WxQidianRedisConfigImpl(redisOps, wxQidianProperties.getConfigStorage().getKeyPrefix()); setWxMpInfo(wxQidianRedisConfig); return wxQidianRedisConfig; } private void setWxMpInfo(WxQidianDefaultConfigImpl config) { WxQidianProperties properties = wxQidianProperties; WxQidianProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); config.setAppId(properties.getAppId()); config.setSecret(properties.getSecret()); config.setToken(properties.getToken()); config.setAesKey(properties.getAesKey()); config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); if (configStorageProperties.getHttpProxyPort() != null) { config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); } } private Pool<Jedis> getJedisPool() { WxQidianProperties.ConfigStorage storage = wxQidianProperties.getConfigStorage(); RedisProperties redis = storage.getRedis(); JedisPoolConfig config = new JedisPoolConfig(); if (redis.getMaxActive() != null) { config.setMaxTotal(redis.getMaxActive()); } if (redis.getMaxIdle() != null) { config.setMaxIdle(redis.getMaxIdle()); } if (redis.getMaxWaitMillis() != null) { config.setMaxWait(Duration.ofMillis(redis.getMaxWaitMillis())); } if (redis.getMinIdle() != null) { config.setMinIdle(redis.getMinIdle()); } config.setTestOnBorrow(true); config.setTestWhileIdle(true); if (StringUtils.isNotEmpty(redis.getSentinelIps())) { Set<String> sentinels = Sets.newHashSet(redis.getSentinelIps().split(",")); return new JedisSentinelPool(redis.getSentinelName(), sentinels,config); } return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/config/WxQidianServiceAutoConfiguration.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/config/WxQidianServiceAutoConfiguration.java
package com.binarywang.solon.wxjava.qidian.config; import com.binarywang.solon.wxjava.qidian.enums.HttpClientType; import com.binarywang.solon.wxjava.qidian.properties.WxQidianProperties; import me.chanjar.weixin.qidian.api.WxQidianService; import me.chanjar.weixin.qidian.api.impl.WxQidianServiceHttpClientImpl; import me.chanjar.weixin.qidian.api.impl.WxQidianServiceImpl; import me.chanjar.weixin.qidian.api.impl.WxQidianServiceJoddHttpImpl; import me.chanjar.weixin.qidian.api.impl.WxQidianServiceOkHttpImpl; import me.chanjar.weixin.qidian.config.WxQidianConfigStorage; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * 腾讯企点相关服务自动注册. * * @author alegria */ @Configuration public class WxQidianServiceAutoConfiguration { @Bean @Condition(onMissingBean = WxQidianService.class) public WxQidianService wxQidianService(WxQidianConfigStorage configStorage, WxQidianProperties wxQidianProperties) { HttpClientType httpClientType = wxQidianProperties.getConfigStorage().getHttpClientType(); WxQidianService wxQidianService; switch (httpClientType) { case OkHttp: wxQidianService = newWxQidianServiceOkHttpImpl(); break; case JoddHttp: wxQidianService = newWxQidianServiceJoddHttpImpl(); break; case HttpClient: wxQidianService = newWxQidianServiceHttpClientImpl(); break; default: wxQidianService = newWxQidianServiceImpl(); break; } wxQidianService.setWxMpConfigStorage(configStorage); return wxQidianService; } private WxQidianService newWxQidianServiceImpl() { return new WxQidianServiceImpl(); } private WxQidianService newWxQidianServiceHttpClientImpl() { return new WxQidianServiceHttpClientImpl(); } private WxQidianService newWxQidianServiceOkHttpImpl() { return new WxQidianServiceOkHttpImpl(); } private WxQidianService newWxQidianServiceJoddHttpImpl() { return new WxQidianServiceJoddHttpImpl(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/HttpClientType.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/HttpClientType.java
package com.binarywang.solon.wxjava.qidian.enums; /** * httpclient类型. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ public enum HttpClientType { /** * HttpClient. */ HttpClient, /** * OkHttp. */ OkHttp, /** * JoddHttp. */ JoddHttp, }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/StorageType.java
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/StorageType.java
package com.binarywang.solon.wxjava.qidian.enums; /** * storage类型. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ public enum StorageType { /** * 内存. */ Memory, /** * redis(JedisClient). */ Jedis, /** * redis(Redisson). */ Redisson, /** * redis(RedisTemplate). */ RedisTemplate }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/test/java/features/test/LoadTest.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/test/java/features/test/LoadTest.java
package features.test; import org.junit.jupiter.api.Test; import org.noear.solon.test.SolonTest; /** * @author noear 2024/9/4 created */ @SolonTest public class LoadTest { @Test public void load(){ } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/service/WxMpMultiServices.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/service/WxMpMultiServices.java
package com.binarywang.solon.wxjava.mp_multi.service; import me.chanjar.weixin.mp.api.WxMpService; /** * 企业微信 {@link WxMpService} 所有实例存放类. * * @author yl * created on 2024/1/23 */ public interface WxMpMultiServices { /** * 通过租户 Id 获取 WxMpService * * @param tenantId 租户 Id * @return WxMpService */ WxMpService getWxMpService(String tenantId); /** * 根据租户 Id,从列表中移除一个 WxMpService 实例 * * @param tenantId 租户 Id */ void removeWxMpService(String tenantId); }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/service/WxMpMultiServicesImpl.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/service/WxMpMultiServicesImpl.java
package com.binarywang.solon.wxjava.mp_multi.service; import me.chanjar.weixin.mp.api.WxMpService; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 企业微信 {@link WxMpMultiServices} 默认实现 * * @author yl * created on 2024/1/23 */ public class WxMpMultiServicesImpl implements WxMpMultiServices { private final Map<String, WxMpService> services = new ConcurrentHashMap<>(); @Override public WxMpService getWxMpService(String tenantId) { return this.services.get(tenantId); } /** * 根据租户 Id,添加一个 WxMpService 到列表 * * @param tenantId 租户 Id * @param wxMpService WxMpService 实例 */ public void addWxMpService(String tenantId, WxMpService wxMpService) { this.services.put(tenantId, wxMpService); } @Override public void removeWxMpService(String tenantId) { this.services.remove(tenantId); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/integration/WxMpMultiPluginImpl.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/integration/WxMpMultiPluginImpl.java
package com.binarywang.solon.wxjava.mp_multi.integration; import com.binarywang.solon.wxjava.mp_multi.configuration.services.WxMpInJedisConfiguration; import com.binarywang.solon.wxjava.mp_multi.configuration.services.WxMpInMemoryConfiguration; import com.binarywang.solon.wxjava.mp_multi.configuration.services.WxMpInRedissonConfiguration; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/9/2 created */ public class WxMpMultiPluginImpl implements Plugin { @Override public void start(AppContext context) throws Throwable { context.beanMake(WxMpMultiProperties.class); context.beanMake(WxMpInJedisConfiguration.class); context.beanMake(WxMpInMemoryConfiguration.class); context.beanMake(WxMpInRedissonConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInRedissonConfiguration.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInRedissonConfiguration.java
package com.binarywang.solon.wxjava.mp_multi.configuration.services; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiProperties; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiRedisProperties; import com.binarywang.solon.wxjava.mp_multi.service.WxMpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpRedissonConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.redisson.config.TransportMode; /** * 自动装配基于 redisson 策略配置 * * @author yl * created on 2024/1/23 */ @Configuration @Condition( onProperty = "${"+WxMpMultiProperties.PREFIX + ".configStorage.type} = redisson", onClass = Redisson.class ) @RequiredArgsConstructor public class WxMpInRedissonConfiguration extends AbstractWxMpConfiguration { private final WxMpMultiProperties wxCpMultiProperties; private final AppContext applicationContext; @Bean public WxMpMultiServices wxMpMultiServices() { return this.wxMpMultiServices(wxCpMultiProperties); } @Override protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) { return this.configRedisson(wxCpMultiProperties); } private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxCpMultiProperties) { WxMpMultiRedisProperties redisProperties = wxCpMultiProperties.getConfigStorage().getRedis(); RedissonClient redissonClient; if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) { redissonClient = getRedissonClient(wxCpMultiProperties); } else { redissonClient = applicationContext.getBean(RedissonClient.class); } return new WxMpRedissonConfigImpl(redissonClient, wxCpMultiProperties.getConfigStorage().getKeyPrefix()); } private RedissonClient getRedissonClient(WxMpMultiProperties wxCpMultiProperties) { WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage(); WxMpMultiRedisProperties redis = storage.getRedis(); Config config = new Config(); config.useSingleServer() .setAddress("redis://" + redis.getHost() + ":" + redis.getPort()) .setDatabase(redis.getDatabase()) .setPassword(redis.getPassword()); config.setTransportMode(TransportMode.NIO); return Redisson.create(config); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInJedisConfiguration.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInJedisConfiguration.java
package com.binarywang.solon.wxjava.mp_multi.configuration.services; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiProperties; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiRedisProperties; import com.binarywang.solon.wxjava.mp_multi.service.WxMpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.common.redis.JedisWxRedisOps; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /** * 自动装配基于 jedis 策略配置 * * @author yl * created on 2024/1/23 */ @Configuration @Condition( onProperty = "${"+WxMpMultiProperties.PREFIX + ".configStorage.type} = jedis", onClass = JedisPool.class ) @RequiredArgsConstructor public class WxMpInJedisConfiguration extends AbstractWxMpConfiguration { private final WxMpMultiProperties wxCpMultiProperties; private final AppContext applicationContext; @Bean public WxMpMultiServices wxMpMultiServices() { return this.wxMpMultiServices(wxCpMultiProperties); } @Override protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) { return this.configRedis(wxCpMultiProperties); } private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxCpMultiProperties) { WxMpMultiRedisProperties wxCpMultiRedisProperties = wxCpMultiProperties.getConfigStorage().getRedis(); JedisPool jedisPool; if (wxCpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpMultiRedisProperties.getHost())) { jedisPool = getJedisPool(wxCpMultiProperties); } else { jedisPool = applicationContext.getBean(JedisPool.class); } return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxCpMultiProperties.getConfigStorage().getKeyPrefix()); } private JedisPool getJedisPool(WxMpMultiProperties wxCpMultiProperties) { WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage(); WxMpMultiRedisProperties redis = storage.getRedis(); JedisPoolConfig config = new JedisPoolConfig(); if (redis.getMaxActive() != null) { config.setMaxTotal(redis.getMaxActive()); } if (redis.getMaxIdle() != null) { config.setMaxIdle(redis.getMaxIdle()); } if (redis.getMaxWaitMillis() != null) { config.setMaxWaitMillis(redis.getMaxWaitMillis()); } if (redis.getMinIdle() != null) { config.setMinIdle(redis.getMinIdle()); } config.setTestOnBorrow(true); config.setTestWhileIdle(true); return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInMemoryConfiguration.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/WxMpInMemoryConfiguration.java
package com.binarywang.solon.wxjava.mp_multi.configuration.services; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiProperties; import com.binarywang.solon.wxjava.mp_multi.service.WxMpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * 自动装配基于内存策略配置 * * @author yl * created on 2024/1/23 */ @Configuration @Condition( onProperty = "${"+WxMpMultiProperties.PREFIX + ".configStorage.type:memory} = memory" ) @RequiredArgsConstructor public class WxMpInMemoryConfiguration extends AbstractWxMpConfiguration { private final WxMpMultiProperties wxCpMultiProperties; @Bean public WxMpMultiServices wxCpMultiServices() { return this.wxMpMultiServices(wxCpMultiProperties); } @Override protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) { return this.configInMemory(); } private WxMpDefaultConfigImpl configInMemory() { return new WxMpMapConfigImpl(); // return new WxMpDefaultConfigImpl(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/AbstractWxMpConfiguration.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/configuration/services/AbstractWxMpConfiguration.java
package com.binarywang.solon.wxjava.mp_multi.configuration.services; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpMultiProperties; import com.binarywang.solon.wxjava.mp_multi.properties.WxMpSingleProperties; import com.binarywang.solon.wxjava.mp_multi.service.WxMpMultiServices; import com.binarywang.solon.wxjava.mp_multi.service.WxMpMultiServicesImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.config.WxMpHostConfig; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import org.apache.commons.lang3.StringUtils; import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * WxMpConfigStorage 抽象配置类 * * @author yl * created on 2024/1/23 */ @RequiredArgsConstructor @Slf4j public abstract class AbstractWxMpConfiguration { protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxCpMultiProperties) { Map<String, WxMpSingleProperties> appsMap = wxCpMultiProperties.getApps(); if (appsMap == null || appsMap.isEmpty()) { log.warn("微信公众号应用参数未配置,通过 WxMpMultiServices#getWxMpService(\"tenantId\")获取实例将返回空"); return new WxMpMultiServicesImpl(); } /** * 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。 * * 查看 {@link me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl#setAppId(String)} */ Collection<WxMpSingleProperties> apps = appsMap.values(); if (apps.size() > 1) { // 校验 appId 是否唯一 boolean multi = apps.stream() // 没有 appId,如果不判断是否为空,这里会报 NPE 异常 .collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting())) .entrySet().stream().anyMatch(e -> e.getValue() > 1); if (multi) { throw new RuntimeException("请确保微信公众号配置 appId 的唯一性"); } } WxMpMultiServicesImpl services = new WxMpMultiServicesImpl(); Set<Map.Entry<String, WxMpSingleProperties>> entries = appsMap.entrySet(); for (Map.Entry<String, WxMpSingleProperties> entry : entries) { String tenantId = entry.getKey(); WxMpSingleProperties wxMpSingleProperties = entry.getValue(); WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxCpMultiProperties); this.configApp(storage, wxMpSingleProperties); this.configHttp(storage, wxCpMultiProperties.getConfigStorage()); this.configHost(storage, wxCpMultiProperties.getHosts()); WxMpService wxCpService = this.wxMpService(storage, wxCpMultiProperties); services.addWxMpService(tenantId, wxCpService); } return services; } /** * 配置 WxMpDefaultConfigImpl * * @param wxMpMultiProperties 参数 * @return WxMpDefaultConfigImpl */ protected abstract WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties); public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpMultiProperties wxMpMultiProperties) { WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage(); WxMpMultiProperties.HttpClientType httpClientType = storage.getHttpClientType(); WxMpService wxMpService; switch (httpClientType) { case OK_HTTP: wxMpService = new WxMpServiceOkHttpImpl(); break; case JODD_HTTP: wxMpService = new WxMpServiceJoddHttpImpl(); break; case HTTP_CLIENT: wxMpService = new WxMpServiceHttpClientImpl(); break; default: wxMpService = new WxMpServiceImpl(); break; } wxMpService.setWxMpConfigStorage(configStorage); int maxRetryTimes = storage.getMaxRetryTimes(); if (maxRetryTimes < 0) { maxRetryTimes = 0; } int retrySleepMillis = storage.getRetrySleepMillis(); if (retrySleepMillis < 0) { retrySleepMillis = 1000; } wxMpService.setRetrySleepMillis(retrySleepMillis); wxMpService.setMaxRetryTimes(maxRetryTimes); return wxMpService; } private void configApp(WxMpDefaultConfigImpl config, WxMpSingleProperties corpProperties) { String appId = corpProperties.getAppId(); String appSecret = corpProperties.getAppSecret(); String token = corpProperties.getToken(); String aesKey = corpProperties.getAesKey(); boolean useStableAccessToken = corpProperties.isUseStableAccessToken(); config.setAppId(appId); config.setSecret(appSecret); if (StringUtils.isNotBlank(token)) { config.setToken(token); } if (StringUtils.isNotBlank(aesKey)) { config.setAesKey(aesKey); } config.setUseStableAccessToken(useStableAccessToken); } private void configHttp(WxMpDefaultConfigImpl config, WxMpMultiProperties.ConfigStorage storage) { String httpProxyHost = storage.getHttpProxyHost(); Integer httpProxyPort = storage.getHttpProxyPort(); String httpProxyUsername = storage.getHttpProxyUsername(); String httpProxyPassword = storage.getHttpProxyPassword(); if (StringUtils.isNotBlank(httpProxyHost)) { config.setHttpProxyHost(httpProxyHost); if (httpProxyPort != null) { config.setHttpProxyPort(httpProxyPort); } if (StringUtils.isNotBlank(httpProxyUsername)) { config.setHttpProxyUsername(httpProxyUsername); } if (StringUtils.isNotBlank(httpProxyPassword)) { config.setHttpProxyPassword(httpProxyPassword); } } } /** * wx host config */ private void configHost(WxMpDefaultConfigImpl config, WxMpMultiProperties.HostConfig hostConfig) { if (hostConfig != null) { String apiHost = hostConfig.getApiHost(); String mpHost = hostConfig.getMpHost(); String openHost = hostConfig.getOpenHost(); WxMpHostConfig wxMpHostConfig = new WxMpHostConfig(); wxMpHostConfig.setApiHost(StringUtils.isNotBlank(apiHost) ? apiHost : null); wxMpHostConfig.setMpHost(StringUtils.isNotBlank(mpHost) ? mpHost : null); wxMpHostConfig.setOpenHost(StringUtils.isNotBlank(openHost) ? openHost : null); config.setHostConfig(wxMpHostConfig); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpSingleProperties.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpSingleProperties.java
package com.binarywang.solon.wxjava.mp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * @author yl * created on 2024/1/23 */ @Data @NoArgsConstructor public class WxMpSingleProperties implements Serializable { private static final long serialVersionUID = 1980986361098922525L; /** * 设置微信公众号的 appid. */ private String appId; /** * 设置微信公众号的 app secret. */ private String appSecret; /** * 设置微信公众号的 token. */ private String token; /** * 设置微信公众号的 EncodingAESKey. */ private String aesKey; /** * 是否使用稳定版 Access Token */ private boolean useStableAccessToken = false; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpMultiRedisProperties.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpMultiRedisProperties.java
package com.binarywang.solon.wxjava.mp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * @author yl * created on 2024/1/23 */ @Data @NoArgsConstructor public class WxMpMultiRedisProperties implements Serializable { private static final long serialVersionUID = -5924815351660074401L; /** * 主机地址. */ private String host = "127.0.0.1"; /** * 端口号. */ private int port = 6379; /** * 密码. */ private String password; /** * 超时. */ private int timeout = 2000; /** * 数据库. */ private int database = 0; /** * sentinel ips */ private String sentinelIps; /** * sentinel name */ private String sentinelName; private Integer maxActive; private Integer maxIdle; private Integer maxWaitMillis; private Integer minIdle; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpMultiProperties.java
solon-plugins/wx-java-mp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp_multi/properties/WxMpMultiProperties.java
package com.binarywang.solon.wxjava.mp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * @author yl * created on 2024/1/23 */ @Data @NoArgsConstructor @Configuration @Inject("${"+WxMpMultiProperties.PREFIX+"}") public class WxMpMultiProperties implements Serializable { private static final long serialVersionUID = -5358245184407791011L; public static final String PREFIX = "wx.mp"; private Map<String, WxMpSingleProperties> apps = new HashMap<>(); /** * 自定义host配置 */ private HostConfig hosts; /** * 存储策略 */ private final ConfigStorage configStorage = new ConfigStorage(); @Data @NoArgsConstructor public static class HostConfig implements Serializable { private static final long serialVersionUID = -4172767630740346001L; /** * 对应于:https://api.weixin.qq.com */ private String apiHost; /** * 对应于:https://open.weixin.qq.com */ private String openHost; /** * 对应于:https://mp.weixin.qq.com */ private String mpHost; } @Data @NoArgsConstructor public static class ConfigStorage implements Serializable { private static final long serialVersionUID = 4815731027000065434L; /** * 存储类型. */ private StorageType type = StorageType.MEMORY; /** * 指定key前缀. */ private String keyPrefix = "wx:mp:multi"; /** * redis连接配置. */ private final WxMpMultiRedisProperties redis = new WxMpMultiRedisProperties(); /** * http客户端类型. */ private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT; /** * http代理主机. */ private String httpProxyHost; /** * http代理端口. */ private Integer httpProxyPort; /** * http代理用户名. */ private String httpProxyUsername; /** * http代理密码. */ private String httpProxyPassword; /** * http 请求最大重试次数 * <pre> * {@link me.chanjar.weixin.mp.api.WxMpService#setMaxRetryTimes(int)} * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)} * </pre> */ private int maxRetryTimes = 5; /** * http 请求重试间隔 * <pre> * {@link me.chanjar.weixin.mp.api.WxMpService#setRetrySleepMillis(int)} * {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)} * </pre> */ private int retrySleepMillis = 1000; } public enum StorageType { /** * 内存 */ MEMORY, /** * jedis */ JEDIS, /** * redisson */ REDISSON, /** * redisTemplate */ REDIS_TEMPLATE } public enum HttpClientType { /** * HttpClient */ HTTP_CLIENT, /** * OkHttp */ OK_HTTP, /** * JoddHttp */ JODD_HTTP } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/test/java/features/test/LoadTest.java
solon-plugins/wx-java-mp-solon-plugin/src/test/java/features/test/LoadTest.java
package features.test; import org.junit.jupiter.api.Test; import org.noear.solon.test.SolonTest; /** * @author noear 2024/9/4 created */ @SolonTest public class LoadTest { @Test public void load(){ } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/integration/WxMpPluginImpl.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/integration/WxMpPluginImpl.java
package com.binarywang.solon.wxjava.mp.integration; import com.binarywang.solon.wxjava.mp.config.WxMpServiceAutoConfiguration; import com.binarywang.solon.wxjava.mp.config.WxMpStorageAutoConfiguration; import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/9/2 created */ public class WxMpPluginImpl implements Plugin { @Override public void start(AppContext context) throws Throwable { context.beanMake(WxMpProperties.class); context.beanMake(WxMpStorageAutoConfiguration.class); context.beanMake(WxMpServiceAutoConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/RedisProperties.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/RedisProperties.java
package com.binarywang.solon.wxjava.mp.properties; import lombok.Data; import java.io.Serializable; /** * redis 配置属性. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ @Data public class RedisProperties implements Serializable { private static final long serialVersionUID = -5924815351660074401L; /** * 主机地址. */ private String host = "127.0.0.1"; /** * 端口号. */ private int port = 6379; /** * 密码. */ private String password; /** * 超时. */ private int timeout = 2000; /** * 数据库. */ private int database = 0; /** * sentinel ips */ private String sentinelIps; /** * sentinel name */ private String sentinelName; private Integer maxActive; private Integer maxIdle; private Integer maxWaitMillis; private Integer minIdle; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/HostConfig.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/HostConfig.java
package com.binarywang.solon.wxjava.mp.properties; import lombok.Data; import java.io.Serializable; @Data public class HostConfig implements Serializable { private static final long serialVersionUID = -4172767630740346001L; /** * 对应于:https://api.weixin.qq.com */ private String apiHost; /** * 对应于:https://open.weixin.qq.com */ private String openHost; /** * 对应于:https://mp.weixin.qq.com */ private String mpHost; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/WxMpProperties.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/WxMpProperties.java
package com.binarywang.solon.wxjava.mp.properties; import com.binarywang.solon.wxjava.mp.enums.HttpClientType; import com.binarywang.solon.wxjava.mp.enums.StorageType; import lombok.Data; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import java.io.Serializable; import static com.binarywang.solon.wxjava.mp.enums.StorageType.Memory; import static com.binarywang.solon.wxjava.mp.properties.WxMpProperties.PREFIX; /** * 微信接入相关配置属性. * * @author someone */ @Data @Configuration @Inject("${" + PREFIX + "}") public class WxMpProperties { public static final String PREFIX = "wx.mp"; /** * 设置微信公众号的appid. */ private String appId; /** * 设置微信公众号的app secret. */ private String secret; /** * 设置微信公众号的token. */ private String token; /** * 设置微信公众号的EncodingAESKey. */ private String aesKey; /** * 是否使用稳定版 Access Token */ private boolean useStableAccessToken = false; /** * 自定义host配置 */ private HostConfig hosts; /** * 存储策略 */ private final ConfigStorage configStorage = new ConfigStorage(); @Data public static class ConfigStorage implements Serializable { private static final long serialVersionUID = 4815731027000065434L; /** * 存储类型. */ private StorageType type = Memory; /** * 指定key前缀. */ private String keyPrefix = "wx"; /** * redis连接配置. */ private final RedisProperties redis = new RedisProperties(); /** * http客户端类型. */ private HttpClientType httpClientType = HttpClientType.HttpClient; /** * http代理主机. */ private String httpProxyHost; /** * http代理端口. */ private Integer httpProxyPort; /** * http代理用户名. */ private String httpProxyUsername; /** * http代理密码. */ private String httpProxyPassword; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpServiceAutoConfiguration.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpServiceAutoConfiguration.java
package com.binarywang.solon.wxjava.mp.config; import com.binarywang.solon.wxjava.mp.enums.HttpClientType; import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * 微信公众号相关服务自动注册. * * @author someone */ @Configuration public class WxMpServiceAutoConfiguration { @Bean @Condition(onMissingBean = WxMpService.class) public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties wxMpProperties) { HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType(); WxMpService wxMpService; switch (httpClientType) { case OkHttp: wxMpService = newWxMpServiceOkHttpImpl(); break; case JoddHttp: wxMpService = newWxMpServiceJoddHttpImpl(); break; case HttpClient: wxMpService = newWxMpServiceHttpClientImpl(); break; default: wxMpService = newWxMpServiceImpl(); break; } wxMpService.setWxMpConfigStorage(configStorage); return wxMpService; } private WxMpService newWxMpServiceImpl() { return new WxMpServiceImpl(); } private WxMpService newWxMpServiceHttpClientImpl() { return new WxMpServiceHttpClientImpl(); } private WxMpService newWxMpServiceOkHttpImpl() { return new WxMpServiceOkHttpImpl(); } private WxMpService newWxMpServiceJoddHttpImpl() { return new WxMpServiceJoddHttpImpl(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpStorageAutoConfiguration.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpStorageAutoConfiguration.java
package com.binarywang.solon.wxjava.mp.config; import com.binarywang.solon.wxjava.mp.enums.StorageType; import com.binarywang.solon.wxjava.mp.properties.RedisProperties; import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.redis.JedisWxRedisOps; import me.chanjar.weixin.common.redis.WxRedisOps; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.config.WxMpHostConfig; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; import redis.clients.jedis.util.Pool; import java.util.Set; /** * 微信公众号存储策略自动配置. * * @author Luo */ @Slf4j @Configuration @RequiredArgsConstructor public class WxMpStorageAutoConfiguration { private final AppContext applicationContext; private final WxMpProperties wxMpProperties; @Bean @Condition(onMissingBean=WxMpConfigStorage.class) public WxMpConfigStorage wxMpConfigStorage() { StorageType type = wxMpProperties.getConfigStorage().getType(); WxMpConfigStorage config; switch (type) { case Jedis: config = jedisConfigStorage(); break; default: config = defaultConfigStorage(); break; } // wx host config if (null != wxMpProperties.getHosts() && StringUtils.isNotEmpty(wxMpProperties.getHosts().getApiHost())) { WxMpHostConfig hostConfig = new WxMpHostConfig(); hostConfig.setApiHost(wxMpProperties.getHosts().getApiHost()); hostConfig.setMpHost(wxMpProperties.getHosts().getMpHost()); hostConfig.setOpenHost(wxMpProperties.getHosts().getOpenHost()); config.setHostConfig(hostConfig); } return config; } private WxMpConfigStorage defaultConfigStorage() { WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); setWxMpInfo(config); return config; } private WxMpConfigStorage jedisConfigStorage() { Pool<Jedis> jedisPool; if (wxMpProperties.getConfigStorage() != null && wxMpProperties.getConfigStorage().getRedis() != null && StringUtils.isNotEmpty(wxMpProperties.getConfigStorage().getRedis().getHost())) { jedisPool = getJedisPool(); } else { jedisPool = applicationContext.getBean(JedisPool.class); } WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix()); setWxMpInfo(wxMpRedisConfig); return wxMpRedisConfig; } private void setWxMpInfo(WxMpDefaultConfigImpl config) { WxMpProperties properties = wxMpProperties; WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); config.setAppId(properties.getAppId()); config.setSecret(properties.getSecret()); config.setToken(properties.getToken()); config.setAesKey(properties.getAesKey()); config.setUseStableAccessToken(wxMpProperties.isUseStableAccessToken()); config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); if (configStorageProperties.getHttpProxyPort() != null) { config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); } } private Pool<Jedis> getJedisPool() { RedisProperties redis = wxMpProperties.getConfigStorage().getRedis(); JedisPoolConfig config = new JedisPoolConfig(); if (redis.getMaxActive() != null) { config.setMaxTotal(redis.getMaxActive()); } if (redis.getMaxIdle() != null) { config.setMaxIdle(redis.getMaxIdle()); } if (redis.getMaxWaitMillis() != null) { config.setMaxWaitMillis(redis.getMaxWaitMillis()); } if (redis.getMinIdle() != null) { config.setMinIdle(redis.getMinIdle()); } config.setTestOnBorrow(true); config.setTestWhileIdle(true); if (StringUtils.isNotEmpty(redis.getSentinelIps())) { Set<String> sentinels = Sets.newHashSet(redis.getSentinelIps().split(",")); return new JedisSentinelPool(redis.getSentinelName(), sentinels); } return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/HttpClientType.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/HttpClientType.java
package com.binarywang.solon.wxjava.mp.enums; /** * httpclient类型. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ public enum HttpClientType { /** * HttpClient. */ HttpClient, /** * OkHttp. */ OkHttp, /** * JoddHttp. */ JoddHttp, }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/StorageType.java
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/StorageType.java
package com.binarywang.solon.wxjava.mp.enums; /** * storage类型. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-30 */ public enum StorageType { /** * 内存. */ Memory, /** * redis(JedisClient). */ Jedis, /** * redis(Redisson). */ Redisson, /** * redis(RedisTemplate). */ RedisTemplate }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-pay-solon-plugin/src/test/java/features/test/LoadTest.java
solon-plugins/wx-java-pay-solon-plugin/src/test/java/features/test/LoadTest.java
package features.test; import org.junit.jupiter.api.Test; import org.noear.solon.test.SolonTest; /** * @author noear 2024/9/4 created */ @SolonTest public class LoadTest { @Test public void load(){ } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/integration/WxPayPluginImpl.java
solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/integration/WxPayPluginImpl.java
package com.binarywang.solon.wxjava.pay.integration; import com.binarywang.solon.wxjava.pay.config.WxPayAutoConfiguration; import com.binarywang.solon.wxjava.pay.properties.WxPayProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/9/2 created */ public class WxPayPluginImpl implements Plugin { @Override public void start(AppContext context) throws Throwable { context.beanMake(WxPayProperties.class); context.beanMake(WxPayAutoConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/properties/WxPayProperties.java
solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/properties/WxPayProperties.java
package com.binarywang.solon.wxjava.pay.properties; import lombok.Data; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; /** * <pre> * 微信支付属性配置类 * Created by Binary Wang on 2019/4/17. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Data @Configuration @Inject("${wx.pay}") public class WxPayProperties { /** * 设置微信公众号或者小程序等的appid. */ private String appId; /** * 微信支付商户号. */ private String mchId; /** * 微信支付商户密钥. */ private String mchKey; /** * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除. */ private String subAppId; /** * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除. */ private String subMchId; /** * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定. */ private String keyPath; /** * 微信支付分serviceId */ private String serviceId; /** * 证书序列号 */ private String certSerialNo; /** * apiV3秘钥 */ private String apiv3Key; /** * 微信支付分回调地址 */ private String payScoreNotifyUrl; /** * apiv3 商户apiclient_key.pem */ private String privateKeyPath; /** * apiv3 商户apiclient_cert.pem */ private String privateCertPath; /** * 微信支付是否使用仿真测试环境. * 默认不使用 */ private boolean useSandboxEnv; /** * 微信支付异步回调地址,通知url必须为直接可访问的url,不能携带参数 */ private String notifyUrl; /** * 微信支付分授权回调地址 */ private String payScorePermissionNotifyUrl; /** * 公钥ID */ private String publicKeyId; /** * pub_key.pem证书文件的绝对路径或者以classpath:开头的类路径. */ private String publicKeyPath; /** * 自定义API主机地址,用于替换默认的 https://api.mch.weixin.qq.com * 例如:http://proxy.company.com:8080 */ private String apiHostUrl; /** * 是否将全部v3接口的请求都添加Wechatpay-Serial请求头,默认不添加 */ private boolean strictlyNeedWechatPaySerial = false; /** * 是否完全使用公钥模式(用以微信从平台证书到公钥的灰度切换),默认不使用 */ private boolean fullPublicKeyModel = false; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/config/WxPayAutoConfiguration.java
solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/config/WxPayAutoConfiguration.java
package com.binarywang.solon.wxjava.pay.config; import com.binarywang.solon.wxjava.pay.properties.WxPayProperties; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * <pre> * 微信支付自动配置 * Created by BinaryWang on 2019/4/17. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Configuration @Condition( onProperty = "${wx.pay.enabled:true} = true", onClass=WxPayService.class ) public class WxPayAutoConfiguration { private WxPayProperties properties; public WxPayAutoConfiguration(WxPayProperties properties) { this.properties = properties; } /** * 构造微信支付服务对象. * * @return 微信支付service */ @Bean @Condition(onMissingBean=WxPayService.class) public WxPayService wxPayService() { final WxPayServiceImpl wxPayService = new WxPayServiceImpl(); WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId())); payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId())); payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv()); payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl())); //以下是apiv3以及支付分相关 payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId())); payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl())); payConfig.setPayScorePermissionNotifyUrl(StringUtils.trimToNull(this.properties.getPayScorePermissionNotifyUrl())); payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath())); payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath())); payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo())); payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key())); payConfig.setPublicKeyId(StringUtils.trimToNull(this.properties.getPublicKeyId())); payConfig.setPublicKeyPath(StringUtils.trimToNull(this.properties.getPublicKeyPath())); payConfig.setApiHostUrl(StringUtils.trimToNull(this.properties.getApiHostUrl())); payConfig.setStrictlyNeedWechatPaySerial(this.properties.isStrictlyNeedWechatPaySerial()); payConfig.setFullPublicKeyModel(this.properties.isFullPublicKeyModel()); wxPayService.setConfig(payConfig); return wxPayService; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/test/java/features/test/LoadTest.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/test/java/features/test/LoadTest.java
package features.test; import org.junit.jupiter.api.Test; import org.noear.solon.test.SolonTest; /** * @author noear 2024/9/4 created */ @SolonTest public class LoadTest { @Test public void load(){ } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/service/WxCpMultiServices.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/service/WxCpMultiServices.java
package com.binarywang.solon.wxjava.cp_multi.service; import me.chanjar.weixin.cp.api.WxCpService; /** * 企业微信 {@link WxCpService} 所有实例存放类. * * @author yl * created on 2023/10/16 */ public interface WxCpMultiServices { /** * 通过租户 Id 获取 WxCpService * * @param tenantId 租户 Id * @return WxCpService */ WxCpService getWxCpService(String tenantId); /** * 根据租户 Id,从列表中移除一个 WxCpService 实例 * * @param tenantId 租户 Id */ void removeWxCpService(String tenantId); }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/service/WxCpMultiServicesImpl.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/service/WxCpMultiServicesImpl.java
package com.binarywang.solon.wxjava.cp_multi.service; import me.chanjar.weixin.cp.api.WxCpService; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 企业微信 {@link WxCpMultiServices} 默认实现 * * @author yl * created on 2023/10/16 */ public class WxCpMultiServicesImpl implements WxCpMultiServices { private final Map<String, WxCpService> services = new ConcurrentHashMap<>(); /** * 通过租户 Id 获取 WxCpService * * @param tenantId 租户 Id * @return WxCpService */ @Override public WxCpService getWxCpService(String tenantId) { return this.services.get(tenantId); } /** * 根据租户 Id,添加一个 WxCpService 到列表 * * @param tenantId 租户 Id * @param wxCpService WxCpService 实例 */ public void addWxCpService(String tenantId, WxCpService wxCpService) { this.services.put(tenantId, wxCpService); } @Override public void removeWxCpService(String tenantId) { this.services.remove(tenantId); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/integration/WxCpMultiPluginImpl.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/integration/WxCpMultiPluginImpl.java
package com.binarywang.solon.wxjava.cp_multi.integration; import com.binarywang.solon.wxjava.cp_multi.configuration.services.WxCpInJedisConfiguration; import com.binarywang.solon.wxjava.cp_multi.configuration.services.WxCpInMemoryConfiguration; import com.binarywang.solon.wxjava.cp_multi.configuration.services.WxCpInRedissonConfiguration; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiProperties; import org.noear.solon.core.AppContext; import org.noear.solon.core.Plugin; /** * @author noear 2024/9/2 created */ public class WxCpMultiPluginImpl implements Plugin { @Override public void start(AppContext context) throws Throwable { context.beanMake(WxCpMultiProperties.class); context.beanMake(WxCpInJedisConfiguration.class); context.beanMake(WxCpInMemoryConfiguration.class); context.beanMake(WxCpInRedissonConfiguration.class); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInRedissonConfiguration.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInRedissonConfiguration.java
package com.binarywang.solon.wxjava.cp_multi.configuration.services; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiProperties; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiRedisProperties; import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import me.chanjar.weixin.cp.config.impl.WxCpRedissonConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.redisson.config.TransportMode; /** * 自动装配基于 redisson 策略配置 * * @author yl * created on 2023/10/16 */ @Configuration @Condition( onProperty = "${"+WxCpMultiProperties.PREFIX + ".configStorage.type} = redisson", onClass = Redisson.class ) @RequiredArgsConstructor public class WxCpInRedissonConfiguration extends AbstractWxCpConfiguration { private final WxCpMultiProperties wxCpMultiProperties; private final AppContext applicationContext; @Bean public WxCpMultiServices wxCpMultiServices() { return this.wxCpMultiServices(wxCpMultiProperties); } @Override protected WxCpDefaultConfigImpl wxCpConfigStorage(WxCpMultiProperties wxCpMultiProperties) { return this.configRedisson(wxCpMultiProperties); } private WxCpDefaultConfigImpl configRedisson(WxCpMultiProperties wxCpMultiProperties) { WxCpMultiRedisProperties redisProperties = wxCpMultiProperties.getConfigStorage().getRedis(); RedissonClient redissonClient; if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) { redissonClient = getRedissonClient(wxCpMultiProperties); } else { redissonClient = applicationContext.getBean(RedissonClient.class); } return new WxCpRedissonConfigImpl(redissonClient, wxCpMultiProperties.getConfigStorage().getKeyPrefix()); } private RedissonClient getRedissonClient(WxCpMultiProperties wxCpMultiProperties) { WxCpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage(); WxCpMultiRedisProperties redis = storage.getRedis(); Config config = new Config(); config.useSingleServer() .setAddress("redis://" + redis.getHost() + ":" + redis.getPort()) .setDatabase(redis.getDatabase()) .setPassword(redis.getPassword()); config.setTransportMode(TransportMode.NIO); return Redisson.create(config); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/AbstractWxCpConfiguration.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/AbstractWxCpConfiguration.java
package com.binarywang.solon.wxjava.cp_multi.configuration.services; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiProperties; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpSingleProperties; import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServices; import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServicesImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.impl.*; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import org.apache.commons.lang3.StringUtils; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * WxCpConfigStorage 抽象配置类 * * @author yl * created on 2023/10/16 */ @RequiredArgsConstructor @Slf4j public abstract class AbstractWxCpConfiguration { protected WxCpMultiServices wxCpMultiServices(WxCpMultiProperties wxCpMultiProperties) { Map<String, WxCpSingleProperties> corps = wxCpMultiProperties.getCorps(); if (corps == null || corps.isEmpty()) { log.warn("企业微信应用参数未配置,通过 WxCpMultiServices#getWxCpService(\"tenantId\")获取实例将返回空"); return new WxCpMultiServicesImpl(); } /** * 校验同一个企业下,agentId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。 * * 查看 {@link me.chanjar.weixin.cp.config.impl.AbstractWxCpInRedisConfigImpl#setAgentId(Integer)} */ Collection<WxCpSingleProperties> corpList = corps.values(); if (corpList.size() > 1) { // 先按 corpId 分组统计 Map<String, List<WxCpSingleProperties>> corpsMap = corpList.stream() .collect(Collectors.groupingBy(WxCpSingleProperties::getCorpId)); Set<Map.Entry<String, List<WxCpSingleProperties>>> entries = corpsMap.entrySet(); for (Map.Entry<String, List<WxCpSingleProperties>> entry : entries) { String corpId = entry.getKey(); // 校验每个企业下,agentId 是否唯一 boolean multi = entry.getValue().stream() // 通讯录没有 agentId,如果不判断是否为空,这里会报 NPE 异常 .collect(Collectors.groupingBy(c -> c.getAgentId() == null ? 0 : c.getAgentId(), Collectors.counting())) .entrySet().stream().anyMatch(e -> e.getValue() > 1); if (multi) { throw new RuntimeException("请确保企业微信配置唯一性[" + corpId + "]"); } } } WxCpMultiServicesImpl services = new WxCpMultiServicesImpl(); Set<Map.Entry<String, WxCpSingleProperties>> entries = corps.entrySet(); for (Map.Entry<String, WxCpSingleProperties> entry : entries) { String tenantId = entry.getKey(); WxCpSingleProperties wxCpSingleProperties = entry.getValue(); WxCpDefaultConfigImpl storage = this.wxCpConfigStorage(wxCpMultiProperties); this.configCorp(storage, wxCpSingleProperties); this.configHttp(storage, wxCpMultiProperties.getConfigStorage()); WxCpService wxCpService = this.wxCpService(storage, wxCpMultiProperties.getConfigStorage()); services.addWxCpService(tenantId, wxCpService); } return services; } /** * 配置 WxCpDefaultConfigImpl * * @param wxCpMultiProperties 参数 * @return WxCpDefaultConfigImpl */ protected abstract WxCpDefaultConfigImpl wxCpConfigStorage(WxCpMultiProperties wxCpMultiProperties); private WxCpService wxCpService(WxCpConfigStorage wxCpConfigStorage, WxCpMultiProperties.ConfigStorage storage) { WxCpMultiProperties.HttpClientType httpClientType = storage.getHttpClientType(); WxCpService wxCpService; switch (httpClientType) { case OK_HTTP: wxCpService = new WxCpServiceOkHttpImpl(); break; case JODD_HTTP: wxCpService = new WxCpServiceJoddHttpImpl(); break; case HTTP_CLIENT: wxCpService = new WxCpServiceApacheHttpClientImpl(); break; case HTTP_COMPONENTS: wxCpService = new WxCpServiceHttpComponentsImpl(); break; default: wxCpService = new WxCpServiceImpl(); break; } wxCpService.setWxCpConfigStorage(wxCpConfigStorage); int maxRetryTimes = storage.getMaxRetryTimes(); if (maxRetryTimes < 0) { maxRetryTimes = 0; } int retrySleepMillis = storage.getRetrySleepMillis(); if (retrySleepMillis < 0) { retrySleepMillis = 1000; } wxCpService.setRetrySleepMillis(retrySleepMillis); wxCpService.setMaxRetryTimes(maxRetryTimes); return wxCpService; } private void configCorp(WxCpDefaultConfigImpl config, WxCpSingleProperties wxCpSingleProperties) { String corpId = wxCpSingleProperties.getCorpId(); String corpSecret = wxCpSingleProperties.getCorpSecret(); Integer agentId = wxCpSingleProperties.getAgentId(); String token = wxCpSingleProperties.getToken(); String aesKey = wxCpSingleProperties.getAesKey(); // 企业微信,私钥,会话存档路径 String msgAuditPriKey = wxCpSingleProperties.getMsgAuditPriKey(); String msgAuditLibPath = wxCpSingleProperties.getMsgAuditLibPath(); config.setCorpId(corpId); config.setCorpSecret(corpSecret); config.setAgentId(agentId); if (StringUtils.isNotBlank(token)) { config.setToken(token); } if (StringUtils.isNotBlank(aesKey)) { config.setAesKey(aesKey); } if (StringUtils.isNotBlank(msgAuditPriKey)) { config.setMsgAuditPriKey(msgAuditPriKey); } if (StringUtils.isNotBlank(msgAuditLibPath)) { config.setMsgAuditLibPath(msgAuditLibPath); } } private void configHttp(WxCpDefaultConfigImpl config, WxCpMultiProperties.ConfigStorage storage) { String httpProxyHost = storage.getHttpProxyHost(); Integer httpProxyPort = storage.getHttpProxyPort(); String httpProxyUsername = storage.getHttpProxyUsername(); String httpProxyPassword = storage.getHttpProxyPassword(); if (StringUtils.isNotBlank(httpProxyHost)) { config.setHttpProxyHost(httpProxyHost); if (httpProxyPort != null) { config.setHttpProxyPort(httpProxyPort); } if (StringUtils.isNotBlank(httpProxyUsername)) { config.setHttpProxyUsername(httpProxyUsername); } if (StringUtils.isNotBlank(httpProxyPassword)) { config.setHttpProxyPassword(httpProxyPassword); } } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInMemoryConfiguration.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInMemoryConfiguration.java
package com.binarywang.solon.wxjava.cp_multi.configuration.services; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiProperties; import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; /** * 自动装配基于内存策略配置 * * @author yl * created on 2023/10/16 */ @Configuration @Condition( onProperty = "${"+WxCpMultiProperties.PREFIX + ".configStorage.type:memory} = memory" ) @RequiredArgsConstructor public class WxCpInMemoryConfiguration extends AbstractWxCpConfiguration { private final WxCpMultiProperties wxCpMultiProperties; @Bean public WxCpMultiServices wxCpMultiServices() { return this.wxCpMultiServices(wxCpMultiProperties); } @Override protected WxCpDefaultConfigImpl wxCpConfigStorage(WxCpMultiProperties wxCpMultiProperties) { return this.configInMemory(); } private WxCpDefaultConfigImpl configInMemory() { return new WxCpDefaultConfigImpl(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInJedisConfiguration.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/configuration/services/WxCpInJedisConfiguration.java
package com.binarywang.solon.wxjava.cp_multi.configuration.services; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiProperties; import com.binarywang.solon.wxjava.cp_multi.properties.WxCpMultiRedisProperties; import com.binarywang.solon.wxjava.cp_multi.service.WxCpMultiServices; import lombok.RequiredArgsConstructor; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import me.chanjar.weixin.cp.config.impl.WxCpJedisConfigImpl; import org.apache.commons.lang3.StringUtils; import org.noear.solon.annotation.Bean; import org.noear.solon.annotation.Condition; import org.noear.solon.annotation.Configuration; import org.noear.solon.core.AppContext; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /** * 自动装配基于 jedis 策略配置 * * @author yl * created on 2023/10/16 */ @Configuration @Condition( onProperty = "${"+WxCpMultiProperties.PREFIX + ".configStorage.type} = jedis", onClass = JedisPool.class ) @RequiredArgsConstructor public class WxCpInJedisConfiguration extends AbstractWxCpConfiguration { private final WxCpMultiProperties wxCpMultiProperties; private final AppContext applicationContext; @Bean public WxCpMultiServices wxCpMultiServices() { return this.wxCpMultiServices(wxCpMultiProperties); } @Override protected WxCpDefaultConfigImpl wxCpConfigStorage(WxCpMultiProperties wxCpMultiProperties) { return this.configRedis(wxCpMultiProperties); } private WxCpDefaultConfigImpl configRedis(WxCpMultiProperties wxCpMultiProperties) { WxCpMultiRedisProperties wxCpMultiRedisProperties = wxCpMultiProperties.getConfigStorage().getRedis(); JedisPool jedisPool; if (wxCpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpMultiRedisProperties.getHost())) { jedisPool = getJedisPool(wxCpMultiProperties); } else { jedisPool = applicationContext.getBean(JedisPool.class); } return new WxCpJedisConfigImpl(jedisPool, wxCpMultiProperties.getConfigStorage().getKeyPrefix()); } private JedisPool getJedisPool(WxCpMultiProperties wxCpMultiProperties) { WxCpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage(); WxCpMultiRedisProperties redis = storage.getRedis(); JedisPoolConfig config = new JedisPoolConfig(); if (redis.getMaxActive() != null) { config.setMaxTotal(redis.getMaxActive()); } if (redis.getMaxIdle() != null) { config.setMaxIdle(redis.getMaxIdle()); } if (redis.getMaxWaitMillis() != null) { config.setMaxWaitMillis(redis.getMaxWaitMillis()); } if (redis.getMinIdle() != null) { config.setMinIdle(redis.getMinIdle()); } config.setTestOnBorrow(true); config.setTestWhileIdle(true); return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpSingleProperties.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpSingleProperties.java
package com.binarywang.solon.wxjava.cp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * 企业微信企业相关配置属性 * * @author yl * created on 2023/10/16 */ @Data @NoArgsConstructor public class WxCpSingleProperties implements Serializable { private static final long serialVersionUID = -7502823825007859418L; /** * 微信企业号 corpId */ private String corpId; /** * 微信企业号 corpSecret */ private String corpSecret; /** * 微信企业号应用 token */ private String token; /** * 微信企业号应用 ID */ private Integer agentId; /** * 微信企业号应用 EncodingAESKey */ private String aesKey; /** * 微信企业号应用 会话存档私钥 */ private String msgAuditPriKey; /** * 微信企业号应用 会话存档类库路径 */ private String msgAuditLibPath; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpMultiRedisProperties.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpMultiRedisProperties.java
package com.binarywang.solon.wxjava.cp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; /** * Redis配置. * * @author yl * created on 2023/10/16 */ @Data @NoArgsConstructor public class WxCpMultiRedisProperties implements Serializable { private static final long serialVersionUID = -5924815351660074401L; /** * 主机地址. */ private String host; /** * 端口号. */ private int port = 6379; /** * 密码. */ private String password; /** * 超时. */ private int timeout = 2000; /** * 数据库. */ private int database = 0; private Integer maxActive; private Integer maxIdle; private Integer maxWaitMillis; private Integer minIdle; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpMultiProperties.java
solon-plugins/wx-java-cp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/cp_multi/properties/WxCpMultiProperties.java
package com.binarywang.solon.wxjava.cp_multi.properties; import lombok.Data; import lombok.NoArgsConstructor; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * 企业微信多企业接入相关配置属性 * * @author yl * created on 2023/10/16 */ @Data @NoArgsConstructor @Configuration @Inject("${" + WxCpMultiProperties.PREFIX + "}") public class WxCpMultiProperties implements Serializable { private static final long serialVersionUID = -1569510477055668503L; public static final String PREFIX = "wx.cp"; private Map<String, WxCpSingleProperties> corps = new HashMap<>(); /** * 配置存储策略,默认内存 */ private ConfigStorage configStorage = new ConfigStorage(); @Data @NoArgsConstructor public static class ConfigStorage implements Serializable { private static final long serialVersionUID = 4815731027000065434L; /** * 存储类型 */ private StorageType type = StorageType.memory; /** * 指定key前缀 */ private String keyPrefix = "wx:cp"; /** * redis连接配置 */ private WxCpMultiRedisProperties redis = new WxCpMultiRedisProperties(); /** * http客户端类型. */ private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT; /** * http代理主机 */ private String httpProxyHost; /** * http代理端口 */ private Integer httpProxyPort; /** * http代理用户名 */ private String httpProxyUsername; /** * http代理密码 */ private String httpProxyPassword; /** * http 请求最大重试次数 * <pre> * {@link me.chanjar.weixin.cp.api.WxCpService#setMaxRetryTimes(int)} * {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setMaxRetryTimes(int)} * </pre> */ private int maxRetryTimes = 5; /** * http 请求重试间隔 * <pre> * {@link me.chanjar.weixin.cp.api.WxCpService#setRetrySleepMillis(int)} * {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setRetrySleepMillis(int)} * </pre> */ private int retrySleepMillis = 1000; } public enum StorageType { /** * 内存 */ memory, /** * jedis */ jedis, /** * redisson */ redisson, /** * redistemplate */ redistemplate } public enum HttpClientType { /** * HttpClient */ HTTP_CLIENT, /** * HttpComponents */ HTTP_COMPONENTS, /** * OkHttp */ OK_HTTP, /** * JoddHttp */ JODD_HTTP } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java
package me.chanjar.weixin.mp.api; import com.google.inject.Inject; import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 测试jsapi ticket接口 * * @author chanjarster */ @Test @Guice(modules = ApiTestModule.class) public class WxMpJsAPITest { @Inject protected WxMpService wxService; public void test() { long timestamp = 1419835025L; String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7"; String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA"; String result = SHA1.genWithAmple( "jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url ); Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java
package me.chanjar.weixin.mp.api; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @Test @Slf4j public class WxMpBusyRetryTest { @DataProvider(name = "getService") public Object[][] getService() { WxMpService service = new WxMpServiceHttpClientImpl() { @Override public synchronized <T, E> T executeInternal( RequestExecutor<T, E> executor, String uri, E data, boolean doNotAutoRefresh) throws WxErrorException { log.info("Executed"); throw new WxErrorException("something"); } }; service.setMaxRetryTimes(3); service.setRetrySleepMillis(500); return new Object[][]{{service}}; } @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) public void testRetry(WxMpService service) throws WxErrorException { service.execute(null, (String) null, null); } @Test(dataProvider = "getService") public void testRetryInThreadPool(final WxMpService service) throws InterruptedException, ExecutionException { // 当线程池中的线程复用的时候,还是能保证相同的重试次数 ExecutorService executorService = Executors.newFixedThreadPool(1); Runnable runnable = () -> { try { System.out.println("====================="); System.out.println(Thread.currentThread().getName() + ": testRetry"); service.execute(null, (String) null, null); } catch (WxErrorException e) { throw new WxRuntimeException(e); } catch (RuntimeException e) { // OK } }; Future<?> submit1 = executorService.submit(runnable); Future<?> submit2 = executorService.submit(runnable); submit1.get(); submit2.get(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java
package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; import org.testng.*; import org.testng.annotations.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.Map; /** * 测试消息路由器 * * @author chanjarster */ @Test public class WxMpMessageRouterTest { @Test(enabled = false) public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { router .rule() .async(async) .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1").content("CONTENT_1") .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) .end() .rule() .async(async) .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK).eventKey("KEY_1") .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) .end() .rule() .async(async) .msgType(WxConsts.XmlMsgType.TEXT).event(WxConsts.EventType.CLICK) .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) .end() .rule().async(async).msgType(WxConsts.XmlMsgType.TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XmlMsgType.TEXT)).end() .rule().async(async).event(WxConsts.EventType.CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EventType.CLICK)).end() .rule().async(async).eventKey("KEY_1").handler(new WxEchoMpMessageHandler(sb, "KEY_1")).end() .rule().async(async).eventKeyRegex("KEY_1*").handler(new WxEchoMpMessageHandler(sb, "KEY_123")).end() .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() .rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() .rule().async(async).matcher(new WxMpMessageMatcher() { @Override public boolean match(WxMpXmlMessage message) { return "strangeformat".equals(message.getFormat()); } }).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() .rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); } @Test(dataProvider = "messages-1") public void testSync(WxMpXmlMessage message, String expected) { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); prepare(false, sb, router); router.route(message); Assert.assertEquals(sb.toString(), expected); } @Test(dataProvider = "messages-1") public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { StringBuffer sb = new StringBuffer(); WxMpMessageRouter router = new WxMpMessageRouter(null); prepare(true, sb, router); router.route(message); Thread.sleep(500); router.shutDownExecutorService(); Assert.assertEquals(sb.toString(), expected); } @Test(dataProvider = "messages-1") public void testExternalExcutorService(WxMpXmlMessage message, String expected) throws InterruptedException { StringBuffer sb = new StringBuffer(); ExecutorService executorService = Executors.newFixedThreadPool(100); WxMpMessageRouter router = new WxMpMessageRouter(null, executorService); prepare(true, sb, router); router.route(message); Thread.sleep(500); executorService.shutdown(); Assert.assertEquals(sb.toString(), expected); } public void testConcurrency() throws InterruptedException { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.rule().handler(new WxMpMessageHandler() { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) { return null; } }).end(); final WxMpXmlMessage m = new WxMpXmlMessage(); Runnable r = () -> { router.route(m); try { Thread.sleep(1000); } catch (InterruptedException e) { } }; for (int i = 0; i < 10; i++) { new Thread(r).start(); } Thread.sleep(2000); } @DataProvider(name = "messages-1") public Object[][] messages2() { WxMpXmlMessage message1 = new WxMpXmlMessage(); message1.setMsgType(WxConsts.XmlMsgType.TEXT); WxMpXmlMessage message2 = new WxMpXmlMessage(); message2.setEvent(WxConsts.EventType.CLICK); WxMpXmlMessage message3 = new WxMpXmlMessage(); message3.setEventKey("KEY_1"); WxMpXmlMessage message4 = new WxMpXmlMessage(); message4.setContent("CONTENT_1"); WxMpXmlMessage message5 = new WxMpXmlMessage(); message5.setContent("BLA"); WxMpXmlMessage message6 = new WxMpXmlMessage(); message6.setContent("abcd"); WxMpXmlMessage message7 = new WxMpXmlMessage(); message7.setFormat("strangeformat"); WxMpXmlMessage c2 = new WxMpXmlMessage(); c2.setMsgType(WxConsts.XmlMsgType.TEXT); c2.setEvent(WxConsts.EventType.CLICK); WxMpXmlMessage c3 = new WxMpXmlMessage(); c3.setMsgType(WxConsts.XmlMsgType.TEXT); c3.setEvent(WxConsts.EventType.CLICK); c3.setEventKey("KEY_1"); WxMpXmlMessage c4 = new WxMpXmlMessage(); c4.setMsgType(WxConsts.XmlMsgType.TEXT); c4.setEvent(WxConsts.EventType.CLICK); c4.setEventKey("KEY_1"); c4.setContent("CONTENT_1"); return new Object[][]{ new Object[]{message1, WxConsts.XmlMsgType.TEXT + ","}, new Object[]{message2, WxConsts.EventType.CLICK + ","}, new Object[]{message3, "KEY_1,"}, new Object[]{message4, "CONTENT_1,"}, new Object[]{message5, "ALL,"}, new Object[]{message6, "abcd,"}, new Object[]{message7, "matcher,"}, new Object[]{c2, "COMBINE_2,"}, new Object[]{c3, "COMBINE_3,"}, new Object[]{c4, "COMBINE_4,"} }; } @DataProvider public Object[][] standardSessionManager() { // 故意把session存活时间变短,清理更频繁 StandardSessionManager ism = new StandardSessionManager(); ism.setMaxInactiveInterval(1); ism.setProcessExpiresFrequency(1); ism.setBackgroundProcessorDelay(1); return new Object[][]{ new Object[]{ism} }; } @Test(dataProvider = "standardSessionManager") public void testSessionClean1(StandardSessionManager ism) throws InterruptedException { // 两个同步请求,看是否处理完毕后会被清理掉 final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(false).handler(new WxSessionMessageHandler()).next() .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } @Test(dataProvider = "standardSessionManager") public void testSessionClean2(StandardSessionManager ism) throws InterruptedException { // 1个同步,1个异步请求,看是否处理完毕后会被清理掉 { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(false).handler(new WxSessionMessageHandler()).next() .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(true).handler(new WxSessionMessageHandler()).next() .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } } @Test(dataProvider = "standardSessionManager") public void testSessionClean3(StandardSessionManager ism) throws InterruptedException { // 2个异步请求,看是否处理完毕后会被清理掉 final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(true).handler(new WxSessionMessageHandler()).next() .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } @Test(dataProvider = "standardSessionManager") public void testSessionClean4(StandardSessionManager ism) throws InterruptedException { // 一个同步请求,看是否处理完毕后会被清理掉 { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(false).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } { final WxMpMessageRouter router = new WxMpMessageRouter(null); router.setSessionManager(ism); router .rule().async(true).handler(new WxSessionMessageHandler()).end(); WxMpXmlMessage msg = new WxMpXmlMessage(); msg.setFromUser("abc"); router.route(msg); Thread.sleep(2000); Assert.assertEquals(ism.getActiveSessions(), 0); } } public static class WxEchoMpMessageHandler implements WxMpMessageHandler { private StringBuffer sb; private String echoStr; public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { this.sb = sb; this.echoStr = echoStr; } @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) { this.sb.append(this.echoStr).append(','); return null; } } public static class WxSessionMessageHandler implements WxMpMessageHandler { @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) { sessionManager.getSession(wxMessage.getFromUser()); return null; } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/ApiTestModule.java
package me.chanjar.weixin.mp.api.test; import java.io.IOException; import java.io.InputStream; import java.util.concurrent.locks.ReentrantLock; import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.inject.Binder; import com.google.inject.Module; import com.thoughtworks.xstream.XStream; import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; public class ApiTestModule implements Module { private final Logger log = LoggerFactory.getLogger(this.getClass()); private static final String TEST_CONFIG_XML = "test-config.xml"; @Override public void configure(Binder binder) { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { if (inputStream == null) { throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); } TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream); config.setAccessTokenLock(new ReentrantLock()); WxMpService mpService = new WxMpServiceHttpClientImpl(); mpService.setWxMpConfigStorage(config); mpService.addConfigStorage("another", config); binder.bind(WxMpConfigStorage.class).toInstance(config); binder.bind(WxMpService.class).toInstance(mpService); } catch (IOException e) { this.log.error(e.getMessage(), e); } } @SuppressWarnings("unchecked") private <T> T fromXml(Class<T> clazz, InputStream is) { XStream xstream = XStreamInitializer.getInstance(); xstream.alias("xml", clazz); xstream.processAnnotations(clazz); return (T) xstream.fromXML(is); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConfigStorage.java
package me.chanjar.weixin.mp.api.test; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.concurrent.locks.Lock; @XStreamAlias("xml") public class TestConfigStorage extends WxMpDefaultConfigImpl { private String openid; private String kfAccount; private String qrconnectRedirectUrl; private String templateId; private String keyPath; public String getKeyPath() { return keyPath; } public void setKeyPath(String keyPath) { this.keyPath = keyPath; } public String getOpenid() { return this.openid; } public void setOpenid(String openid) { this.openid = openid; } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } public String getKfAccount() { return this.kfAccount; } public void setKfAccount(String kfAccount) { this.kfAccount = kfAccount; } public String getQrconnectRedirectUrl() { return this.qrconnectRedirectUrl; } public void setQrconnectRedirectUrl(String qrconnectRedirectUrl) { this.qrconnectRedirectUrl = qrconnectRedirectUrl; } @Override public String getTemplateId() { return this.templateId; } @Override public void setTemplateId(String templateId) { this.templateId = templateId; } public void setAccessTokenLock(Lock lock) { super.accessTokenLock = lock; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConstants.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/test/TestConstants.java
package me.chanjar.weixin.mp.api.test; /** * <pre> * 仅供测试使用的一些常量 * Created by Binary Wang on 2017-3-9. * </pre> */ public class TestConstants { /////////////////////// // 文件类型 /////////////////////// public static final String FILE_JPG = "jpeg"; public static final String FILE_MP3 = "mp3"; public static final String FILE_AMR = "amr"; public static final String FILE_MP4 = "mp4"; }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.datacube.*; import org.apache.commons.lang3.time.FastDateFormat; import org.testng.*; import org.testng.annotations.*; import java.text.ParseException; import java.util.Date; import java.util.List; /** * 测试统计分析相关的接口 * Created by Binary Wang on 2016/8/23. * * @author binarywang (https://github.com/binarywang) */ @Guice(modules = ApiTestModule.class) public class WxMpDataCubeServiceImplTest { @Inject protected WxMpService wxService; private FastDateFormat simpleDateFormat = FastDateFormat .getInstance("yyyy-MM-dd"); @DataProvider public Object[][] oneDay() throws ParseException { return new Object[][]{{this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] threeDays() throws ParseException { return new Object[][]{{this.simpleDateFormat.parse("2016-08-20"), this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] sevenDays() throws ParseException { return new Object[][]{{this.simpleDateFormat.parse("2016-08-16"), this.simpleDateFormat.parse("2016-08-22")}}; } @DataProvider public Object[][] fifteenDays() throws ParseException { return new Object[][]{{this.simpleDateFormat.parse("2016-08-14"), this.simpleDateFormat.parse("2016-08-27")}}; } @DataProvider public Object[][] thirtyDays() throws ParseException { return new Object[][]{{this.simpleDateFormat.parse("2016-07-30"), this.simpleDateFormat.parse("2016-08-27")}}; } @Test(dataProvider = "sevenDays") public void testGetUserSummary(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeUserSummary> summaries = this.wxService.getDataCubeService() .getUserSummary(beginDate, endDate); Assert.assertNotNull(summaries); System.out.println(summaries); } @Test(dataProvider = "sevenDays") public void testGetUserCumulate(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeUserCumulate> result = this.wxService.getDataCubeService() .getUserCumulate(beginDate, endDate); Assert.assertNotNull(result); System.out.println(result); } @Test(dataProvider = "oneDay") public void testGetArticleSummary(Date date) throws WxErrorException { List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() .getArticleSummary(date, date); Assert.assertNotNull(results); System.out.println(results); } /** * TODO 该接口,暂时没找到有数据的日期,无法测试验证 */ @Test(dataProvider = "oneDay") public void testGetArticleTotal(Date date) throws WxErrorException { List<WxDataCubeArticleTotal> results = this.wxService.getDataCubeService() .getArticleTotal(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "threeDays") public void testGetUserRead(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() .getUserRead(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "oneDay") public void testGetUserReadHour(Date date) throws WxErrorException { List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() .getUserReadHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "sevenDays") public void testGetUserShare(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() .getUserShare(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "oneDay") public void testGetUserShareHour(Date date) throws WxErrorException { List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() .getUserShareHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "sevenDays") public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsg(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "oneDay") public void testGetUpstreamMsgHour(Date date) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgHour(date, date); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } /** * TODO 该接口,暂时没找到有数据的日期,无法测试验证 */ @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "fifteenDays") public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgDist(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgDistWeek(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } /** * TODO 该接口,暂时没找到有数据的日期,无法测试验证 */ @Test(dataProvider = "thirtyDays") public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() .getUpstreamMsgDistMonth(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "thirtyDays") public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() .getInterfaceSummary(beginDate, endDate); Assert.assertNotNull(results); System.out.println(results); } @Test(dataProvider = "oneDay") public void testGetInterfaceSummaryHour(Date date) throws WxErrorException { List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() .getInterfaceSummaryHour(date, date); Assert.assertNotNull(results); System.out.println(results); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpSubscribeMsgServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * @author Mklaus * created on 2018-01-22 下午2:02 */ @Guice(modules = ApiTestModule.class) public class WxMpSubscribeMsgServiceImplTest { @Inject protected WxMpService wxService; @Test public void testSendSubscribeOnceMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpSubscribeMessage message = WxMpSubscribeMessage.builder() .title("weixin test") .toUser(configStorage.getOpenid()) .scene("1000") .contentColor("#FF0000") .contentValue("Send subscribe message test") .build(); try { boolean send = this.wxService.getSubscribeMsgService().sendOnce(message); Assert.assertTrue(send); } catch (WxErrorException e) { // 当用户没有授权,获取之前的授权已使用。微信会返回错误代码 {"errcode":43101,"errmsg":"user refuse to accept the msg hint: [xxxxxxxxxxx]"} if (e.getError().getErrorCode() != 43101) { throw e; } } } @Test public void testSubscribeMsgAuthorizationUrl() { } @Test public void testGetPubTemplateTitleList() { } @Test public void testGetPubTemplateKeyWordsById() { } @Test public void testAddTemplate() { } @Test public void testGetTemplateList() { } @Test public void testDelTemplate() { } @Test public void testGetCategory() { } @Test public void testSend() { } @Test public void testSendOnce() { } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOAuth2ServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOAuth2ServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import me.chanjar.weixin.common.bean.WxOAuth2UserInfo; import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import org.testng.annotations.Guice; import org.testng.annotations.Test; import javax.inject.Inject; import static org.assertj.core.api.Assertions.assertThat; /** * 测试类. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-08-09 */ @Test @Guice(modules = ApiTestModule.class) public class WxMpOAuth2ServiceImplTest { @Inject private WxMpService mpService; @Test public void testBuildAuthorizationUrl() { final String url = this.mpService.getOAuth2Service().buildAuthorizationUrl("http://www.baidu.com", "test", "GOD"); assertThat(url).isEqualTo("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + this.mpService.getWxMpConfigStorage().getAppId() + "&redirect_uri=http%3A%2F%2Fwww.baidu.com&response_type=code&scope=test&state=GOD&connect_redirect=1#wechat_redirect"); } @Test public void testGetAccessToken() throws WxErrorException { final WxOAuth2AccessToken accessToken = this.mpService.getOAuth2Service().getAccessToken("11"); assertThat(accessToken).isNotNull(); } @Test public void testRefreshAccessToken() throws WxErrorException { final WxOAuth2AccessToken accessToken = this.mpService.getOAuth2Service().refreshAccessToken("11"); assertThat(accessToken).isNotNull(); } @Test public void testGetUserInfo() throws WxErrorException { final WxOAuth2AccessToken accessToken = this.mpService.getOAuth2Service().getAccessToken("11"); final WxOAuth2UserInfo userInfo = this.mpService.getOAuth2Service().getUserInfo(accessToken, null); assertThat(userInfo).isNotNull(); } @Test public void testValidateAccessToken() { final boolean result = this.mpService.getOAuth2Service().validateAccessToken(new WxOAuth2AccessToken()); assertThat(result).isTrue(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import org.apache.commons.lang3.StringUtils; import org.testng.*; import org.testng.annotations.*; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.config.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo; import me.chanjar.weixin.common.enums.TicketType; import static org.testng.Assert.*; @Test @Guice(modules = ApiTestModule.class) public class WxMpServiceImplTest { @Inject private WxMpService wxService; @Test public void testGetCurrentAutoReplyInfo() throws WxErrorException { WxMpCurrentAutoReplyInfo autoReplyInfo = this.wxService.getCurrentAutoReplyInfo(); assertNotNull(autoReplyInfo); System.out.println(autoReplyInfo); } @Test public void testClearQuota() throws WxErrorException { this.wxService.clearQuota(wxService.getWxMpConfigStorage().getAppId()); } @Test public void testBuildQrConnectUrl() { String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, WxConsts.QrConnectScope.SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } @Test public void testBuildQrConnectRedirectUrl() { String qrConnectRedirectUrl = this.wxService.getWxMpConfigStorage().getQrConnectRedirectUrl(); String qrConnectUrl = this.wxService.buildQrConnectUrl(qrConnectRedirectUrl, WxConsts.QrConnectScope.SNSAPI_LOGIN, null); Assert.assertNotNull(qrConnectUrl); System.out.println(qrConnectUrl); } public void testGetTicket() throws WxErrorException { String ticket = this.wxService.getTicket(TicketType.SDK, false); System.out.println(ticket); Assert.assertNotNull(ticket); } public void testRefreshAccessToken() throws WxErrorException { WxMpConfigStorage configStorage = this.wxService.getWxMpConfigStorage(); String before = configStorage.getAccessToken(); this.wxService.getAccessToken(false); String after = configStorage.getAccessToken(); Assert.assertNotEquals(before, after); Assert.assertTrue(StringUtils.isNotBlank(after)); } public void testStableRefreshAccessToken() throws WxErrorException { WxMpConfigStorage configStorage = this.wxService.getWxMpConfigStorage(); configStorage.useStableAccessToken(true); String before = configStorage.getAccessToken(); this.wxService.getAccessToken(false); String after = configStorage.getAccessToken(); Assert.assertNotEquals(before, after); Assert.assertTrue(StringUtils.isNotBlank(after)); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.template.*; import org.apache.commons.lang3.RandomStringUtils; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; /** * <pre> * Created by Binary Wang on 2016-10-14. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Guice(modules = ApiTestModule.class) public class WxMpTemplateMsgServiceImplTest { @Inject protected WxMpService wxService; @Test(invocationCount = 5, threadPoolSize = 3) public void testSendTemplateMsg() throws WxErrorException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() .toUser(configStorage.getOpenid()) .templateId(configStorage.getTemplateId()) .url(" ") .build(); templateMessage.addData(new WxMpTemplateData("first", dateFormat.format(new Date()), "#FF00FF")) .addData(new WxMpTemplateData("remark", RandomStringUtils.randomAlphanumeric(100), "#FF00FF")); String msgId = this.wxService.getTemplateMsgService().sendTemplateMsg(templateMessage); Assert.assertNotNull(msgId); System.out.println(msgId); } @Test public void testGetIndustry() throws Exception { final WxMpTemplateIndustry industry = this.wxService.getTemplateMsgService().getIndustry(); Assert.assertNotNull(industry); System.out.println(industry); } @Test public void testSetIndustry() throws Exception { WxMpTemplateIndustry industry = new WxMpTemplateIndustry(WxMpTemplateIndustryEnum.findByCode(29), WxMpTemplateIndustryEnum.findByCode(8)); boolean result = this.wxService.getTemplateMsgService().setIndustry(industry); Assert.assertTrue(result); } @Test public void testAddTemplate() throws Exception { String result = this.wxService.getTemplateMsgService().addTemplate("TM00015"); Assert.assertNotNull(result); System.err.println(result); } @Test public void testGetAllPrivateTemplate() throws Exception { List<WxMpTemplate> result = this.wxService.getTemplateMsgService().getAllPrivateTemplate(); Assert.assertNotNull(result); System.err.println(result); } @Test public void testDelPrivateTemplate() throws Exception { String templateId = "RPcTe7-4BkU5A2J3imC6W0b4JbjEERcJg0whOMKJKIc"; boolean result = this.wxService.getTemplateMsgService().delPrivateTemplate(templateId); Assert.assertTrue(result); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpWifiServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopDataResult; import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.BIZWIFI_SHOP_GET; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * <pre> * Created by BinaryWang on 2018/6/10. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class WxMpWifiServiceImplTest { @Inject private WxMpService wxService; @Test public void testListShop() throws WxErrorException { final WxMpWifiShopListResult result = this.wxService.getWifiService().listShop(1, 2); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testGetShopWifiInfo() throws WxErrorException { final WxMpWifiShopDataResult wifiInfo = this.wxService.getWifiService().getShopWifiInfo(123); assertThat(wifiInfo).isNotNull(); System.out.println(wifiInfo); } @Test public void testUpdateShopWifiInfo() throws WxErrorException { final boolean result = this.wxService.getWifiService() .updateShopWifiInfo(123, "123", "345", null); assertThat(result).isTrue(); } public static class MockTest { private WxMpService wxService = mock(WxMpService.class); @Test public void testGetShopWifiInfo() throws Exception { String returnJson = "{\n" + " \"errcode\": 0,\n" + " \"data\": {\n" + " \"shop_name\": \"南山店\",\n" + " \"ssid\": \" WX123\",\n" + " \"ssid_list\": [\n" + " \"WX123\",\n" + " \"WX456\"\n" + " ],\n" + " \"ssid_password_list\": [\n" + " {\n" + " \"ssid\": \"WX123\",\n" + " \"password\": \"123456789\"\n" + " },\n" + " {\n" + " \"ssid\": \"WX456\",\n" + " \"password\": \"21332465dge\"\n" + " }\n" + " ],\n" + " \"password\": \"123456789\",\n" + " \"protocol_type\": 4,\n" + " \"ap_count\": 2,\n" + " \"template_id\": 1,\n" + " \"homepage_url\": \"http://www.weixin.qq.com/\",\n" + " \"bar_type\": 1,\n" + " \"sid\":\"\",\n" + " \"poi_id\":\"285633617\"\n" + " }\n" + "}"; when(wxService.post(eq(BIZWIFI_SHOP_GET), anyString())).thenReturn(returnJson); when(wxService.getWifiService()).thenReturn(new WxMpWifiServiceImpl(wxService)); final WxMpWifiShopDataResult wifiInfo = this.wxService.getWifiService().getShopWifiInfo(123); assertThat(wifiInfo).isNotNull(); System.out.println(wifiInfo); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * 单元测试. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2020-10-06 */ @Guice(modules = ApiTestModule.class) public class WxMpGuideServiceImplTest { @Inject protected WxMpService wxService; /** * 顾问微信号 guide_account */ private static final String ACCOUNT = "sxc_Warm"; @Test public void testAddGuide() throws WxErrorException { this.wxService.getGuideService().addGuide(ACCOUNT, "", null, null); } @Test public void testAddGuide_another() throws WxErrorException { this.wxService.getGuideService().addGuide(WxMpGuideInfo.builder().account(ACCOUNT).build()); } @Test public void testGetGuide() throws WxErrorException { final WxMpGuideInfo guideInfo = this.wxService.getGuideService().getGuide(ACCOUNT, null); assertThat(guideInfo).isNotNull(); } @Test public void testUpdateGuide() throws WxErrorException { this.wxService.getGuideService().updateGuide(WxMpGuideInfo.builder().account(ACCOUNT).nickName("我是谁").build()); } @Test public void testDelGuide() throws WxErrorException { this.wxService.getGuideService().delGuide(ACCOUNT, null); } @Test public void testListGuide() throws WxErrorException { final WxMpGuideList guideList = this.wxService.getGuideService().listGuide(0, 10); assertThat(guideList).isNotNull(); } @Test public void testCreateGuideQrCode() throws WxErrorException { String guideQrCode = this.wxService.getGuideService().createGuideQrCode(ACCOUNT, null, null); assertThat(guideQrCode).isNotNull(); } @Test public void testGetGuideChatRecord() throws WxErrorException { final WxMpGuideMsgList guideChatRecord = this.wxService.getGuideService().getGuideChatRecord(ACCOUNT, null, null, null, null, 0, 10); assertThat(guideChatRecord).isNotNull(); } @Test public void testSetGuideConfig() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("自动回复设置" + ACCOUNT); list.add("自动回复设置" + ACCOUNT); this.wxService.getGuideService().setGuideConfig(null, null, true, list, WxMpAddGuideAutoReply.builder().content("欢迎测试1").msgType(1).build(), WxMpAddGuideAutoReply.builder().content("欢迎测试2").msgType(1).build()); } @Test public void testGetGuideConfig() throws WxErrorException { final WxMpGuideConfig guideConfig = this.wxService.getGuideService().getGuideConfig(ACCOUNT, null); assertThat(guideConfig).isNotNull(); } @Test public void testSetGuideAcctConfig() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("敏感词1"); list.add("敏感词2"); this.wxService.getGuideService().setGuideAcctConfig(false, list, "离线自动回复"); } @Test public void testGetGuideAcctConfig() throws WxErrorException { final WxMpGuideAcctConfig guideAcctConfig = this.wxService.getGuideService().getGuideAcctConfig(); assertThat(guideAcctConfig).isNotNull(); } @Test public void testPushShowWxaPathMenu() throws WxErrorException { this.wxService.getGuideService().pushShowWxaPathMenu("wx4f793c04fd3be5a8", ACCOUNT); } @Test public void testNewGuideGroup() throws WxErrorException { Long id = this.wxService.getGuideService().newGuideGroup("顾问分组名称"); assertThat(id).isNotNull(); } @Test public void testGetGuideGroup() throws WxErrorException { List<WxMpGuideGroup> guideGroupList = this.wxService.getGuideService().getGuideGroupList(); assertThat(guideGroupList).isNotNull(); } @Test public void testGetGroupInfo() throws WxErrorException { WxMpGuideGroupInfoList groupInfo = this.wxService.getGuideService().getGroupInfo(1860131524965138433L, 0, 10); assertThat(groupInfo).isNotNull(); } @Test public void testAddGuide2GuideGroup() throws WxErrorException { this.wxService.getGuideService().addGuide2GuideGroup(1860131524965138433L, ACCOUNT); } @Test public void testDelGuide2GuideGroup() throws WxErrorException { this.wxService.getGuideService().delGuide2GuideGroup(1860131524965138433L, ACCOUNT); } @Test public void testGetGroupByGuide() throws WxErrorException { List<Long> groupByGuide = this.wxService.getGuideService().getGroupByGuide(ACCOUNT); assertThat(groupByGuide).isNotNull(); } @Test public void testDelGuideGroup() throws WxErrorException { this.wxService.getGuideService().delGuideGroup(1860131524965138433L); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserBlacklistServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import org.testng.*; import org.testng.annotations.*; import javax.inject.Inject; import java.util.ArrayList; import java.util.List; /** * @author miller */ @Test(groups = "userAPI") @Guice(modules = ApiTestModule.class) public class WxMpUserBlacklistServiceImplTest { @Inject protected WxMpService wxService; @Test public void testGetBlacklist() throws Exception { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); Assert.assertNotNull(wxMpUserBlacklistGetResult); Assert.assertFalse(wxMpUserBlacklistGetResult.getCount() == -1); Assert.assertFalse(wxMpUserBlacklistGetResult.getTotal() == -1); Assert.assertFalse(wxMpUserBlacklistGetResult.getOpenidList().size() == -1); System.out.println(wxMpUserBlacklistGetResult); } @Test public void testPushToBlacklist() throws Exception { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List<String> openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); this.wxService.getBlackListService().pushToBlacklist(openidList); } @Test public void testPullFromBlacklist() throws Exception { TestConfigStorage configStorage = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); List<String> openidList = new ArrayList<>(); openidList.add(configStorage.getOpenid()); this.wxService.getBlackListService().pullFromBlacklist(openidList); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideBuyerServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideBuyerServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://www.sacoc.cn">广州跨界-宋心成</a> * created on 2021/5/13/013 */ @Guice(modules = ApiTestModule.class) public class WxMpGuideBuyerServiceImplTest { @Inject protected WxMpService wxService; /** * 顾问微信号 guide_account */ private static final String ACCOUNT = "sxc_Warm"; @Test public void testAddGuideBuyerRelation() throws WxErrorException { List<WxMpAddGuideBuyerInfo> list = new ArrayList<>(); list.add(WxMpAddGuideBuyerInfo.builder().nickname("小执花").openid("oqlk8v0uTJgRnn5eEskNruD4-bc8").build()); List<WxMpGuideBuyerResp> wxMpGuideBuyerResps = this.wxService.getGuideBuyerService().addGuideBuyerRelation(ACCOUNT, null, list); assertThat(wxMpGuideBuyerResps).isNotNull(); } @Test public void testAddGuideBuyerRelationOnce() throws WxErrorException { this.wxService.getGuideBuyerService().addGuideBuyerRelation(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8", "小执花"); } @Test public void testDelGuideBuyerRelation() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("oqlk8v0uTJgRnn5eEskNruD4-bc8"); List<WxMpGuideBuyerResp> wxMpGuideBuyerResps = this.wxService.getGuideBuyerService().delGuideBuyerRelation(ACCOUNT, null, list); assertThat(wxMpGuideBuyerResps).isNotNull(); } @Test public void testDelGuideBuyerRelationOnce() throws WxErrorException { this.wxService.getGuideBuyerService().delGuideBuyerRelation(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8"); } @Test public void testGetGuideBuyerRelationList() throws WxErrorException { WxMpGuideBuyerInfoList list = this.wxService.getGuideBuyerService().getGuideBuyerRelationList(ACCOUNT, null, 0, 10); assertThat(list).isNotNull(); } @Test public void testRebindGuideAcctForBuyer() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("oqlk8v0uTJgRnn5eEskNruD4-bc8"); list.add("oqlk8vybPMWapMwOfFTFVYqWpGM0"); List<WxMpGuideBuyerResp> enemytriplekill = this.wxService.getGuideBuyerService().rebindGuideAcctForBuyer(ACCOUNT, null, "enemytriplekill", null, list); assertThat(enemytriplekill).isNotNull(); } @Test public void testRebindGuideAcctForBuyerOnce() throws WxErrorException { this.wxService.getGuideBuyerService().rebindGuideAcctForBuyer(ACCOUNT, null, "enemytriplekill", null, "oqlk8v0uTJgRnn5eEskNruD4-bc8"); } @Test public void testUpdateGuideBuyerRelation() throws WxErrorException { this.wxService.getGuideBuyerService().updateGuideBuyerRelation(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8", "微信文档有坑"); } @Test public void testGetGuideBuyerRelationByBuyer() throws WxErrorException { WxMpGuideBuyerRelation guideBuyerRelationByBuyer = this.wxService.getGuideBuyerService().getGuideBuyerRelationByBuyer("oqlk8v0uTJgRnn5eEskNruD4-bc8"); assertThat(guideBuyerRelationByBuyer).isNotNull(); } @Test public void testGetGuideBuyerRelation() throws WxErrorException { WxMpGuideBuyerInfo guideBuyerRelation = this.wxService.getGuideBuyerService().getGuideBuyerRelation(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8"); assertThat(guideBuyerRelation).isNotNull(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; import org.testng.annotations.*; import java.math.BigDecimal; import java.util.List; import static org.testng.AssertJUnit.*; /** * Created by Binary Wang on 2016-09-23. * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class WxMpStoreServiceImplTest { @Inject private WxMpService wxMpService; /** * Test method for {@link WxMpStoreServiceImpl#add(WxMpStoreBaseInfo)}. */ public void testAdd() throws WxErrorException { this.wxMpService.getStoreService() .add(WxMpStoreBaseInfo.builder() .businessName("haha") .branchName("abc") .province("aaa") .district("aaa") .telephone("122") .address("abc") .categories(new String[]{"美食,江浙菜"}) .longitude(new BigDecimal("115.32375")) .latitude(new BigDecimal("25.097486")) .city("aaa") .build()); // 以下运行会抛异常 this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); } public void testUpdate() throws WxErrorException { this.wxMpService.getStoreService() .update(WxMpStoreBaseInfo.builder() .poiId("291503654") .telephone("020-12345678") .sid("aaa") .avgPrice(35) .openTime("8:00-20:00") .special("免费wifi,外卖服务") .introduction("麦当劳是全球大型跨国连锁餐厅,1940 年创立于美国,在世界上大约拥有3 万间分店。主要售卖汉堡包,以及薯条、炸鸡、汽水、冰品、沙拉、水果等快餐食品") .build()); } public void testGet() throws WxErrorException { WxMpStoreBaseInfo result = this.wxMpService.getStoreService().get("291503654"); assertNotNull(result); System.err.println(result); } public void testDelete() throws WxErrorException { this.wxMpService.getStoreService().delete("463558057"); } public void testListCategories() throws WxErrorException { List<String> result = this.wxMpService.getStoreService().listCategories(); assertNotNull(result); System.err.println(result); } public void testList() throws WxErrorException { WxMpStoreListResult result = this.wxMpService.getStoreService().list(0, 10); assertNotNull(result); System.err.println(result); } public void testListAll() throws WxErrorException { List<WxMpStoreInfo> list = this.wxMpService.getStoreService().listAll(); assertNotNull(list); System.err.println(list.size()); System.err.println(list); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.common.collect.Sets; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxNetCheckResult; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxMpErrorMsgEnum; import me.chanjar.weixin.common.util.http.HttpClientType; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder; import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.testng.Assert.*; /** * <pre> * Created by BinaryWang on 2019/3/29. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class BaseWxMpServiceImplTest { @Inject private WxMpService wxService; @Test public void testSwitchover() { assertTrue(this.wxService.switchover("another")); assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another"); assertFalse(this.wxService.switchover("whatever")); assertFalse(this.wxService.switchover("default")); } @Test public void testSwitchoverTo() throws WxErrorException { assertThat(this.wxService.switchoverTo("another").getAccessToken()).isNotEmpty(); assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another"); } @Test public void testNetCheck() throws WxErrorException { WxNetCheckResult result = this.wxService.netCheck(WxConsts.NetCheckArgs.ACTIONALL, WxConsts.NetCheckArgs.OPERATORDEFAULT); Assert.assertNotNull(result); } @Test public void testGetCallbackIP() throws WxErrorException { String[] ipArray = this.wxService.getCallbackIP(); System.out.println(Arrays.toString(ipArray)); Assert.assertNotNull(ipArray); Assert.assertNotEquals(ipArray.length, 0); } public void testShortUrl() throws WxErrorException { String shortUrl = this.wxService.shortUrl("http://www.baidu.com/test?access_token=123"); assertThat(shortUrl).isNotEmpty(); System.out.println(shortUrl); } @Test(expectedExceptions = WxErrorException.class) public void testShortUrl_with_exceptional_url() throws WxErrorException { this.wxService.shortUrl("http://www.baidu.com/test?redirect_count=1&access_token=123"); } @Test public void refreshAccessTokenDuplicatelyTest() throws InterruptedException { // 测试多线程刷新accessToken时是否重复刷新 wxService.getWxMpConfigStorage().expireAccessToken(); final Set<String> set = Sets.newConcurrentHashSet(); Runnable r = () -> { try { String accessToken = wxService.getAccessToken(); set.add(accessToken); } catch (WxErrorException e) { e.printStackTrace(); } }; final int threadNumber = 10; ExecutorService executorService = Executors.newFixedThreadPool(threadNumber); for (int i = 0; i < threadNumber; i++) { executorService.submit(r); } executorService.shutdown(); boolean isTerminated = executorService.awaitTermination(15, TimeUnit.SECONDS); System.out.println("isTerminated: " + isTerminated); System.out.println("times of refreshing accessToken: " + set.size()); assertEquals(set.size(), 1); } @Test public void testCheckSignature() { } @Test public void testGetTicket() { } @Test public void testTestGetTicket() { } @Test public void testGetJsapiTicket() { } @Test public void testTestGetJsapiTicket() { } @Test public void testCreateJsapiSignature() throws WxErrorException { final WxJsapiSignature jsapiSignature = this.wxService.createJsapiSignature("http://www.baidu.com"); assertThat(jsapiSignature).isNotNull(); assertThat(jsapiSignature.getSignature()).isNotNull(); System.out.println(jsapiSignature); } @Test public void testGetAccessToken() { } @Test public void testSemanticQuery() { } @Test public void testOauth2buildAuthorizationUrl() { } @Test public void testBuildQrConnectUrl() { } @Test public void testOauth2getAccessToken() { } @Test public void testOauth2refreshAccessToken() { } @Test public void testOauth2getUserInfo() { } @Test public void testOauth2validateAccessToken() { } @Test public void testGetCurrentAutoReplyInfo() { } @Test public void testClearQuota() { } @Test public void testGet() { } @Test public void testTestGet() { } @Test public void testPost() { } @Test public void testTestPost() { } @Test public void testExecute() throws WxErrorException, IOException { } @Test public void testExecuteAutoRefreshToken() throws WxErrorException, IOException { //测试access token获取时的重试机制 BaseWxMpServiceImpl<Object, Object> service = new BaseWxMpServiceImpl() { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { return "模拟一个过期的access token:" + System.currentTimeMillis(); } @Override protected String doGetAccessTokenRequest() throws IOException { return null; } @Override protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException { return null; } @Override public void initHttp() { } @Override public Object getRequestHttpClient() { return null; } @Override public Object getRequestHttpProxy() { return null; } @Override public HttpClientType getRequestType() { return null; } }; WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); config.setAppId("1"); service.setWxMpConfigStorage(config); RequestExecutor<Object, Object> re = mock(RequestExecutor.class); AtomicInteger counter = new AtomicInteger(); Mockito.when(re.execute(Mockito.anyString(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> { counter.incrementAndGet(); WxError error = WxError.builder().errorCode(WxMpErrorMsgEnum.CODE_40001.getCode()).errorMsg(WxMpErrorMsgEnum.CODE_40001.getMsg()).build(); throw new WxErrorException(error); }); try { Object execute = service.execute(re, "http://baidu.com", new HashMap<>()); Assert.assertTrue(false, "代码应该不会执行到这里"); } catch (WxErrorException e) { Assert.assertEquals(WxMpErrorMsgEnum.CODE_40001.getCode(), e.getError().getErrorCode()); Assert.assertEquals(2, counter.get()); } } @Test public void testTestExecute() { } @Test public void testExecuteInternal() { } @Test public void testGetWxMpConfigStorage() { } @Test public void testSetWxMpConfigStorage() { } @Test public void testSetMultiConfigStorages() { } @Test public void testTestSetMultiConfigStorages() { } @Test public void testAddConfigStorage() { } @Test public void testRemoveConfigStorage() { } @Test public void testSetRetrySleepMillis() { } @Test public void testSetMaxRetryTimes() { } @Test public void testGetKefuService() { } @Test public void testGetMaterialService() { } @Test public void testGetMenuService() { } @Test public void testGetUserService() { } @Test public void testGetUserTagService() { } @Test public void testGetQrcodeService() { } @Test public void testGetCardService() { } @Test public void testGetDataCubeService() { } @Test public void testGetBlackListService() { } @Test public void testGetStoreService() { } @Test public void testGetTemplateMsgService() { } @Test public void testGetSubscribeMsgService() { } @Test public void testGetDeviceService() { } @Test public void testGetShakeService() { } @Test public void testGetMemberCardService() { } @Test public void testGetRequestHttp() { } @Test public void testGetMassMessageService() { } @Test public void testSetKefuService() { } @Test public void testSetMaterialService() { } @Test public void testSetMenuService() { } @Test public void testSetUserService() { } @Test public void testSetTagService() { } @Test public void testSetQrCodeService() { } @Test public void testSetCardService() { } @Test public void testSetStoreService() { } @Test public void testSetDataCubeService() { } @Test public void testSetBlackListService() { } @Test public void testSetTemplateMsgService() { } @Test public void testSetDeviceService() { } @Test public void testSetShakeService() { } @Test public void testSetMemberCardService() { } @Test public void testSetMassMessageService() { } @Test public void testGetAiOpenService() { } @Test public void testSetAiOpenService() { } @Test public void testGetWifiService() { } @Test public void testGetOcrService() { } @Test public void testGetMarketingService() { } @Test public void testSetMarketingService() { } @Test public void testSetOcrService() { } @Test public void testGetCommentService() { } @Test public void testSetCommentService() { } @Test public void testGetImgProcService() { } @Test public void testSetImgProcService() { } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.common.collect.Lists; import com.google.inject.Inject; import me.chanjar.weixin.common.bean.WxCardApiSignature; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.card.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; /** * 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 * Created by Binary Wang on 2016/7/27. * * @author binarywang (https://github.com/binarywang) */ @Test @Guice(modules = ApiTestModule.class) public class WxMpCardServiceImplTest { @Inject protected WxMpService wxService; private String cardId = "123"; private String code = "good"; private String openid = "abc"; @Test public void testGetCardApiTicket() throws Exception { String cardApiTicket = this.wxService.getCardService().getCardApiTicket(); assertNotNull(cardApiTicket); System.out.println(cardApiTicket); } @Test public void testGetCardApiTicketWithParam() throws Exception { String cardApiTicket = this.wxService.getCardService().getCardApiTicket(true); assertNotNull(cardApiTicket); System.out.println(cardApiTicket); } @Test public void testCreateCardApiSignature() throws Exception { //app_id, card_id, card_type, code, openid, location_id String[] param = {"123", this.cardId, "", this.code, this.openid, ""}; WxCardApiSignature cardApiSignature = this.wxService.getCardService().createCardApiSignature(param); assertNotNull(cardApiSignature); System.out.println(cardApiSignature); } @Test public void testDecryptCardCode() throws Exception { String encryptCode = "pd0vTUHSHc9tMUCL2gXABcUmINm6yxqJh0y9Phsy63E="; String cardCode = this.wxService.getCardService().decryptCardCode(encryptCode); assertNotNull(cardCode); System.out.println(cardCode); } @Test public void testQueryCardCode() throws Exception { WxMpCardResult wxMpCardResult = this.wxService.getCardService().queryCardCode(this.cardId, this.code, false); assertNotNull(wxMpCardResult); System.out.println(wxMpCardResult); } @Test public void testConsumeCardCode() throws Exception { String result = this.wxService.getCardService().consumeCardCode(this.code); assertNotNull(result); System.out.println(result); } @Test public void testConsumeCardCodeWithCardId() throws Exception { String result = this.wxService.getCardService().consumeCardCode(this.code, this.cardId); assertNotNull(result); System.out.println(result); } @Test public void testMarkCardCode() throws Exception { this.wxService.getCardService().markCardCode(this.code, this.cardId, this.openid, true); System.out.println("done"); } @Test public void testGetCardDetail() throws Exception { String result = this.wxService.getCardService().getCardDetail(this.cardId); assertNotNull(result); System.out.println(result); } @Test public void testUnavailableCardCode() throws Exception { String cardId = "p2iQk1luzj50RHue6yeTPQpAx_Z4"; String code = "134905347310"; String reason = "换成新卡了"; String result = this.wxService.getCardService().unavailableCardCode(cardId, code, reason); assertNotNull(result); System.out.println(result); } @Test public void testCreateGrouponCard() throws WxErrorException { BaseInfo base = new BaseInfo(); base.setLogoUrl("http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0"); base.setBrandName("测试优惠券"); base.setCodeType("CODE_TYPE_QRCODE"); base.setTitle("测试标题"); base.setColor("Color010"); base.setNotice("测试Notice"); base.setServicePhone("020-88888888"); base.setDescription("不可与其他优惠同享\\n如需团购券发票,请在消费时向商户提出\\n店内均可使用,仅限堂食"); DateInfo info = new DateInfo(); info.setType("DATE_TYPE_FIX_TERM"); info.setFixedBeginTerm(0); info.setFixedTerm(30); base.setDateInfo(info); Sku sku = new Sku(); sku.setQuantity(100); base.setSku(sku); base.setGetLimit(1); base.setCanShare(true); base.setCanGiveFriend(true); base.setUseAllLocations(true); base.setCenterTitle("顶部居中按钮"); base.setCenterSubTitle("按钮下方的wording"); base.setCenterUrl("www.qq.com"); base.setCustomUrl("http://www.qq.com"); base.setCustomUrlName("立即使用"); base.setCustomUrlSubTitle("副标题tip"); base.setPromotionUrlName("更多优惠"); base.setPromotionUrl("http://www.qq.com"); base.setLocationIdList(Lists.newArrayList("1234")); //团购券 WxMpCardCreateRequest grouponMessage = new WxMpCardCreateRequest(); GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest(); GrouponCard grouponCard = new GrouponCard(); grouponCard.setBaseInfo(base); grouponCard.setDealDetail("deal detail"); grouponCardCreateRequest.setGroupon(grouponCard); grouponMessage.setCardCreateRequest(grouponCardCreateRequest); System.out.println(this.wxService.getCardService().createCard(grouponMessage)); //现金券 WxMpCardCreateRequest cashMessage = new WxMpCardCreateRequest(); CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest(); CashCard cashCard = new CashCard(); cashCard.setBaseInfo(base); cashCard.setLeastCost(1000); cashCard.setReduceCost(100); cashCardCreateRequest.setCash(cashCard); cashMessage.setCardCreateRequest(cashCardCreateRequest); System.out.println(this.wxService.getCardService().createCard(cashMessage)); //折扣券 WxMpCardCreateRequest discountMessage = new WxMpCardCreateRequest(); DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest(); DiscountCard discountCard = new DiscountCard(); discountCard.setBaseInfo(base); discountCard.setDiscount(30); discountCardCreateRequest.setDiscount(discountCard); discountMessage.setCardCreateRequest(discountCardCreateRequest); System.out.println(this.wxService.getCardService().createCard(discountMessage)); //兑换券 WxMpCardCreateRequest giftMessage = new WxMpCardCreateRequest(); GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest(); GiftCard giftCard = new GiftCard(); giftCard.setBaseInfo(base); giftCard.setGift("星巴克雪瑞纳咖啡大杯"); giftCardCreateRequest.setGift(giftCard); giftMessage.setCardCreateRequest(giftCardCreateRequest); System.out.println(this.wxService.getCardService().createCard(giftMessage)); //普通兑换券 WxMpCardCreateRequest generalMessage = new WxMpCardCreateRequest(); GeneralCouponCreateRequest generalCouponCreateRequest = new GeneralCouponCreateRequest(); GeneralCoupon generalCoupon = new GeneralCoupon(); generalCoupon.setBaseInfo(base); generalCoupon.setDefaultDetail("音乐木盒"); generalCouponCreateRequest.setGeneralCoupon(generalCoupon); generalMessage.setCardCreateRequest(generalCouponCreateRequest); System.out.println(this.wxService.getCardService().createCard(generalMessage)); } @Test public void testDeleteCard() throws Exception { String cardId = "pwkrWjtw7W4_l50kCQcZ1in1yS6g"; WxMpCardDeleteResult result = this.wxService.getCardService().deleteCard(cardId); assertTrue(result.isSuccess()); System.out.println(result); } @Test public void testAddTestWhiteList() { } @Test public void testCreateCard() { } @Test public void testCreateQrcodeCard() { } @Test public void testCreateQrcodeCard1() { } @Test public void testCreateQrcodeCard2() { } @Test public void testCreateLandingPage() { } @Test public void testGetUserCardList() throws WxErrorException { String openId = "ou7Gr5sJZgFGgj38sRCNQg5pc3Fc"; String cardId = "pu7Gr5secJXPkxBeuYUhmp8TYsuY"; WxUserCardListResult result = this.wxService.getCardService().getUserCardList(openId, cardId); assertNotNull(result); System.out.println(result); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; import org.testng.annotations.*; /** * Created by keungtung on 14/12/2016. */ @Test(groups = "deviceApi") @Guice(modules = ApiTestModule.class) public class WxMpDeviceServiceImplTest { @Inject protected WxMpService wxService; @Test(dataProvider = "productId") public void testGetQrcode(String productId) { try { WxDeviceQrCodeResult result = wxService.getDeviceService().getQrCode(productId); println(result.toJson()); } catch (WxErrorException e) { println(e.getMessage()); } } private void println(String content) { System.out.println(content); } @DataProvider(name = "productId") public Object[][] getProductId() { return new Object[][]{new Object[]{"25639"}}; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConstants; import me.chanjar.weixin.common.bean.ocr.WxOcrBankCardResult; import me.chanjar.weixin.common.bean.ocr.WxOcrBizLicenseResult; import me.chanjar.weixin.common.bean.ocr.WxOcrCommResult; import me.chanjar.weixin.common.bean.ocr.WxOcrDrivingLicenseResult; import me.chanjar.weixin.common.bean.ocr.WxOcrDrivingResult; import me.chanjar.weixin.common.bean.ocr.WxOcrIdCardResult; import org.testng.annotations.Guice; import org.testng.annotations.Test; import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * 测试类. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-06-22 */ @Test @Guice(modules = ApiTestModule.class) public class WxMpOcrServiceImplTest { @Inject private WxMpService service; @Test public void testIdCard() throws WxErrorException { final WxOcrIdCardResult result = this.service.getOcrService().idCard( "https://res.wx.qq.com/op_res/E_oqdHqP4ETOJsT46sQnXz1HbeHOpqDQTuhkYeaLaJTf-JKld7de3091dwxCQwa6"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testIdCard2() throws Exception { InputStream inputStream = this.getImageStream("https://res.wx.qq.com/op_res/E_oqdHqP4ETOJsT46sQnXz1HbeHOpqDQTuhkYeaLaJTf-JKld7de3091dwxCQwa6"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrIdCardResult result = this.service.getOcrService().idCard(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBankCard() throws WxErrorException { final WxOcrBankCardResult result = this.service.getOcrService().bankCard("https://res.wx.qq.com/op_res/eP7PObYbBJj-_19EbGBL4PWe_zQ1NwET5NXSugjEWc-4ayns4Q-HFJrp-AOog8ih"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBankCard2() throws Exception { InputStream inputStream = this.getImageStream("https://res.wx.qq.com/op_res/eP7PObYbBJj-_19EbGBL4PWe_zQ1NwET5NXSugjEWc-4ayns4Q-HFJrp-AOog8ih"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrBankCardResult result = this.service.getOcrService().bankCard(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDriving() throws WxErrorException { final WxOcrDrivingResult result = this.service.getOcrService().driving("https://res.wx.qq.com/op_res/T051P5uWvh9gSJ9j78tWib53WiNi2pHSSZhoO8wnY3Av-djpsA4kA9whbtt6_Tb6"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDriving2() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrDrivingResult result = this.service.getOcrService().driving(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDrivingLicense() throws WxErrorException { final WxOcrDrivingLicenseResult result = this.service.getOcrService().drivingLicense("https://res.wx.qq.com/op_res/kD4YXjYVAW1eaQqn9uTA0rrOFoZRvVINitNDSGo5gJ7SzTCezNq_ZDDmU1I08kGn"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDrivingLicense2() throws Exception { InputStream inputStream = this.getImageStream("https://res.wx.qq.com/op_res/kD4YXjYVAW1eaQqn9uTA0rrOFoZRvVINitNDSGo5gJ7SzTCezNq_ZDDmU1I08kGn"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrDrivingLicenseResult result = this.service.getOcrService().drivingLicense(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBizLicense() throws WxErrorException { final WxOcrBizLicenseResult result = this.service.getOcrService().bizLicense("https://res.wx.qq.com/op_res/apCy0YbnEdjYsa_cjW6x3FlpCc20uQ-2BYE7aXnFsrB-ALHZNgdKXhzIUcrRnDoL"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBizLicense2() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrBizLicenseResult result = this.service.getOcrService().bizLicense(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testComm() throws WxErrorException { final WxOcrCommResult result = this.service.getOcrService().comm("https://res.wx.qq.com/op_res/apCy0YbnEdjYsa_cjW6x3FlpCc20uQ-2BYE7aXnFsrB-ALHZNgdKXhzIUcrRnDoL"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testComm2() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxOcrCommResult result = this.service.getOcrService().comm(tempFile); assertThat(result).isNotNull(); System.out.println(result); } private InputStream getImageStream(String url) { try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestMethod("GET"); if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) { return connection.getInputStream(); } } catch (IOException e) { System.out.println("获取网络图片出现异常,图片路径为:" + url); } return null; } public static class MockTest { private final WxMpService wxService = mock(WxMpService.class); @Test public void testIdCard() throws Exception { String returnJson = "{\"type\":\"Back\",\"name\":\"张三\",\"id\":\"110101199909090099\",\"valid_date\":\"20110101-20210201\"}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrIdCardResult result = wxMpOcrService.idCard("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBankCard() throws Exception { String returnJson = "{\"number\":\"24234234345234\"}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrBankCardResult result = wxMpOcrService.bankCard("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDriving() throws Exception { String returnJson = "{\n" + " \"errcode\": 0,\n" + " \"errmsg\": \"ok\",\n" + " \"plate_num\": \"粤xxxxx\", //车牌号码\n" + " \"vehicle_type\": \"小型普通客车\", //车辆类型\n" + " \"owner\": \"东莞市xxxxx机械厂\", //所有人\n" + " \"addr\": \"广东省东莞市xxxxx号\", //住址\n" + " \"use_character\": \"非营运\", //使用性质\n" + " \"model\": \"江淮牌HFCxxxxxxx\", //品牌型号\n" + " \"vin\": \"LJ166xxxxxxxx51\", //车辆识别代号\n" + " \"engine_num\": \"J3xxxxx3\", //发动机号码\n" + " \"register_date\": \"2018-07-06\", //注册日期\n" + " \"issue_date\": \"2018-07-01\", //发证日期\n" + " \"plate_num_b\": \"粤xxxxx\", //车牌号码\n" + " \"record\": \"441xxxxxx3\", //号牌\n" + " \"passengers_num\": \"7人\", //核定载人数\n" + " \"total_quality\": \"2700kg\", //总质量\n" + " \"prepare_quality\": \"1995kg\", //整备质量\n" + " \"overall_size\": \"4582x1795x1458mm\", //外廓尺寸\n" + " \"card_position_front\": {//卡片正面位置(检测到卡片正面才会返回)\n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 119, \n" + " \"y\": 2925\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 1435, \n" + " \"y\": 2887\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 1435, \n" + " \"y\": 3793\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 119, \n" + " \"y\": 3831\n" + " }\n" + " }\n" + " }, \n" + " \"card_position_back\": {//卡片反面位置(检测到卡片反面才会返回)\n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 1523, \n" + " \"y\": 2849\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 2898, \n" + " \"y\": 2887\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 2927, \n" + " \"y\": 3831\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 1523, \n" + " \"y\": 3831\n" + " }\n" + " }\n" + " }, \n" + " \"img_size\": {//图片大小\n" + " \"w\": 3120, \n" + " \"h\": 4208\n" + " }\n" + "}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrDrivingResult result = wxMpOcrService.driving("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testDrivingLicense() throws Exception { String returnJson = "{\n" + " \"errcode\": 0,\n" + " \"errmsg\": \"ok\",\n" + " \"id_num\": \"660601xxxxxxxx1234\", //证号\n" + " \"name\": \"张三\", //姓名\n" + " \"sex\": \"男\", //性别\n" + " \"nationality\": \"中国\", //国籍\n" + " \"address\": \"广东省东莞市xxxxx号\", //住址\n" + " \"birth_date\": \"1990-12-21\", //出生日期\n" + " \"issue_date\": \"2012-12-21\", //初次领证日期\n" + " \"car_class\": \"C1\", //准驾车型\n" + " \"valid_from\": \"2018-07-06\", //有效期限起始日\n" + " \"valid_to\": \"2020-07-01\", //有效期限终止日\n" + " \"official_seal\": \"xx市公安局公安交通管理局\" //印章文字\n" + "}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrDrivingLicenseResult result = wxMpOcrService.drivingLicense("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testBizLicense() throws Exception { String returnJson = "{\n" + " \"errcode\": 0, \n" + " \"errmsg\": \"ok\", \n" + " \"reg_num\": \"123123\",//注册号\n" + " \"serial\": \"123123\",//编号\n" + " \"legal_representative\": \"张三\", //法定代表人姓名\n" + " \"enterprise_name\": \"XX饮食店\", //企业名称\n" + " \"type_of_organization\": \"个人经营\", //组成形式\n" + " \"address\": \"XX市XX区XX路XX号\", //经营场所/企业住所\n" + " \"type_of_enterprise\": \"xxx\", //公司类型\n" + " \"business_scope\": \"中型餐馆(不含凉菜、不含裱花蛋糕,不含生食海产品)。\", //经营范围\n" + " \"registered_capital\": \"200万\", //注册资本\n" + " \"paid_in_capital\": \"200万\", //实收资本\n" + " \"valid_period\": \"2019年1月1日\", //营业期限\n" + " \"registered_date\": \"2018年1月1日\", //注册日期/成立日期\n" + " \"cert_position\": { //营业执照位置\n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 155, \n" + " \"y\": 191\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 725, \n" + " \"y\": 157\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 743, \n" + " \"y\": 512\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 164, \n" + " \"y\": 525\n" + " }\n" + " }\n" + " }, \n" + " \"img_size\": { //图片大小\n" + " \"w\": 966, \n" + " \"h\": 728\n" + " }\n" + "}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrBizLicenseResult result = wxMpOcrService.bizLicense("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testComm() throws Exception { String returnJson = "{\n" + " \"errcode\": 0, \n" + " \"errmsg\": \"ok\", \n" + " \"items\": [ //识别结果\n" + " {\n" + " \"text\": \"腾讯\", \n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 575, \n" + " \"y\": 519\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 744, \n" + " \"y\": 519\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 744, \n" + " \"y\": 532\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 573, \n" + " \"y\": 532\n" + " }\n" + " }\n" + " }, \n" + " {\n" + " \"text\": \"微信团队\", \n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 670, \n" + " \"y\": 516\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 762, \n" + " \"y\": 517\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 762, \n" + " \"y\": 532\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 670, \n" + " \"y\": 531\n" + " }\n" + " }\n" + " }\n" + " ], \n" + " \"img_size\": { //图片大小\n" + " \"w\": 1280, \n" + " \"h\": 720\n" + " }\n" + "}"; when(wxService.post(anyString(), anyString())).thenReturn(returnJson); final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); final WxOcrCommResult result = wxMpOcrService.comm("abc"); assertThat(result).isNotNull(); System.out.println(result); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import java.io.File; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Date; import org.testng.annotations.*; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfInfo; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfList; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfMsgList; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionGetResult; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionList; import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfSessionWaitCaseList; import static org.assertj.core.api.Assertions.assertThat; /** * 测试客服相关接口 * * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) public class WxMpKefuServiceImplTest { @Inject protected WxMpService wxService; public void testSendKefuMpNewsMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.MPNEWS); message.setToUser(configStorage.getOpenid()); message.setMpNewsMediaId("52R6dL2FxDpM9N1rCY3sYBqHwq-L7K_lz1sPI71idMg"); boolean result = this.wxService.getKefuService().sendKefuMessage(message); assertThat(result).isTrue(); } public void testSendKefuMessage() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); boolean result = this.wxService.getKefuService().sendKefuMessage(message); assertThat(result).isTrue(); } public void testSendKefuMessageWithKfAccount() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); boolean result = this.wxService.getKefuService().sendKefuMessage(message); assertThat(result).isTrue(); } public void testKfList() throws WxErrorException { WxMpKfList kfList = this.wxService.getKefuService().kfList(); assertThat(kfList).isNotNull(); for (WxMpKfInfo k : kfList.getKfList()) { System.err.println(k); } } public void testKfOnlineList() throws WxErrorException { WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList(); assertThat(kfOnlineList).isNotNull(); for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { System.err.println(k); } } @DataProvider public Object[][] getKfAccount() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); return new Object[][]{{configStorage.getKfAccount()}}; } @Test(dataProvider = "getKfAccount") public void testKfAccountAdd(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).nickName("我晕").build(); assertThat(this.wxService.getKefuService().kfAccountAdd(request)).isTrue(); } @Test(dependsOnMethods = { "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountUpdate(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).nickName("我晕").build(); assertThat(this.wxService.getKefuService().kfAccountUpdate(request)).isTrue(); } @Test(dependsOnMethods = { "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).inviteWx(" ").build(); assertThat(this.wxService.getKefuService().kfAccountInviteWorker(request)).isTrue(); } @Test(dependsOnMethods = {"testKfAccountUpdate", "testKfAccountAdd"}, dataProvider = "getKfAccount") public void testKfAccountUploadHeadImg(String kfAccount) throws WxErrorException { File imgFile = new File("src\\test\\resources\\mm.jpeg"); boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(kfAccount, imgFile); assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccount") public void testKfAccountDel(String kfAccount) throws WxErrorException { boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount); assertThat(result).isTrue(); } @DataProvider public Object[][] getKfAccountAndOpenid() { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); return new Object[][]{{configStorage.getKfAccount(), configStorage.getOpenid()}}; } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionCreate(String kfAccount, String openid) throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionCreate(openid, kfAccount); assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionClose(String kfAccount, String openid) throws WxErrorException { boolean result = this.wxService.getKefuService().kfSessionClose(openid, kfAccount); assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, String openid) throws WxErrorException { WxMpKfSessionGetResult result = this.wxService.getKefuService().kfSessionGet(openid); assertThat(result).isNotNull(); System.err.println(result); } @Test(dataProvider = "getKfAccount") public void testKfSessionList(String kfAccount) throws WxErrorException { WxMpKfSessionList result = this.wxService.getKefuService().kfSessionList(kfAccount); assertThat(result).isNotNull(); System.err.println(result); } @Test public void testKfSessionGetWaitCase() throws WxErrorException { WxMpKfSessionWaitCaseList result = this.wxService.getKefuService().kfSessionGetWaitCase(); assertThat(result).isNotNull(); System.err.println(result); } @Test public void testKfMsgList() throws WxErrorException { // Date startTime = DateTime.now().minusDays(1).toDate(); // Date endTime = DateTime.now().minusDays(0).toDate(); Date startTime = Date.from(Instant.now().minus(1, ChronoUnit.DAYS)); Date endTime = Date.from(Instant.now()); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50); assertThat(result).isNotNull(); System.err.println(result); } @Test public void testKfMsgListAll() throws WxErrorException { // Date startTime = DateTime.now().minusDays(1).toDate(); // Date endTime = DateTime.now().minusDays(0).toDate(); Date startTime = Date.from(Instant.now().minus(1, ChronoUnit.DAYS)); Date endTime = Date.from(Instant.now()); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime); assertThat(result).isNotNull(); System.err.println(result); } @Test public void testSendKfTypingState() throws WxErrorException { TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); boolean result = this.wxService.getKefuService().sendKfTypingState(configStorage.getOpenid(), "Typing"); assertThat(result).isTrue(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpImgProcServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpImgProcServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.service.WxImgProcService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConstants; import me.chanjar.weixin.common.bean.imgproc.WxImgProcAiCropResult; import me.chanjar.weixin.common.bean.imgproc.WxImgProcQrCodeResult; import me.chanjar.weixin.common.bean.imgproc.WxImgProcSuperResolutionResult; import org.testng.annotations.Guice; import org.testng.annotations.Test; import javax.inject.Inject; import java.io.File; import java.io.InputStream; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @Test @Guice(modules = ApiTestModule.class) public class WxMpImgProcServiceImplTest { @Inject private WxMpService mpService; @Test public void testQrCode() throws WxErrorException { final WxImgProcQrCodeResult result = this.mpService.getImgProcService().qrCode("https://gitee.com/binary/weixin-java-tools/raw/master/images/qrcodes/mp.png"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testQrCode2() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxImgProcQrCodeResult result = this.mpService.getImgProcService().qrCode(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testSuperResolution() throws WxErrorException { final WxImgProcSuperResolutionResult result = this.mpService.getImgProcService().superResolution("https://gitee.com/binary/weixin-java-tools/raw/master/images/qrcodes/mp.png"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testSuperResolution2() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxImgProcSuperResolutionResult result = this.mpService.getImgProcService().superResolution(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testAiCrop() throws WxErrorException { final WxImgProcAiCropResult result = this.mpService.getImgProcService().aiCrop("https://gitee.com/binary/weixin-java-tools/images/banners/wiki.jpg"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testAiCrop2() throws WxErrorException { final WxImgProcAiCropResult result = this.mpService.getImgProcService().aiCrop("https://gitee.com/binary/weixin-java-tools/images/banners/wiki.jpg", "1,2.35"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testAiCrop3() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxImgProcAiCropResult result = this.mpService.getImgProcService().aiCrop(tempFile); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testAiCrop4() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); final WxImgProcAiCropResult result = this.mpService.getImgProcService().aiCrop(tempFile, "1,2.35,3.5"); assertThat(result).isNotNull(); System.out.println(result); } public static class mockTest { private WxMpService wxService = mock(WxMpService.class); @Test public void testQrCode() throws Exception { String returnJson = "{\n" + " \"errcode\": 0, \n" + " \"errmsg\": \"ok\", \n" + " \"code_results\": [\n" + " {\n" + " \"type_name\": \"QR_CODE\", \n" + " \"data\": \"https://www.qq.com\", \n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 585, \n" + " \"y\": 378\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 828, \n" + " \"y\": 378\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 828, \n" + " \"y\": 618\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 585, \n" + " \"y\": 618\n" + " }\n" + " }\n" + " }, \n" + " {\n" + " \"type_name\": \"QR_CODE\", \n" + " \"data\": \"https://mp.weixin.qq.com\", \n" + " \"pos\": {\n" + " \"left_top\": {\n" + " \"x\": 185, \n" + " \"y\": 142\n" + " }, \n" + " \"right_top\": {\n" + " \"x\": 396, \n" + " \"y\": 142\n" + " }, \n" + " \"right_bottom\": {\n" + " \"x\": 396, \n" + " \"y\": 353\n" + " }, \n" + " \"left_bottom\": {\n" + " \"x\": 185, \n" + " \"y\": 353\n" + " }\n" + " }\n" + " }, \n" + " {\n" + " \"type_name\": \"EAN_13\", \n" + " \"data\": \"5906789678957\"\n" + " }, \n" + " {\n" + " \"type_name\": \"CODE_128\", \n" + " \"data\": \"50090500019191\"\n" + " }\n" + " ], \n" + " \"img_size\": {\n" + " \"w\": 1000, \n" + " \"h\": 900\n" + " }\n" + "}"; when(wxService.get(anyString(), anyString())).thenReturn(returnJson); final WxImgProcService wxMpImgProcService = new WxMpImgProcServiceImpl(wxService); final WxImgProcQrCodeResult result = wxMpImgProcService.qrCode("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testSuperResolution() throws Exception { String returnJson = "{\n" + " \"errcode\": 0, \n" + " \"errmsg\": \"ok\", \n" + " \"media_id\": \"6WXsIXkG7lXuDLspD9xfm5dsvHzb0EFl0li6ySxi92ap8Vl3zZoD9DpOyNudeJGB\"\n" + "}"; when(wxService.get(anyString(), anyString())).thenReturn(returnJson); final WxImgProcService wxMpImgProcService = new WxMpImgProcServiceImpl(wxService); final WxImgProcSuperResolutionResult result = wxMpImgProcService.superResolution("abc"); assertThat(result).isNotNull(); System.out.println(result); } @Test public void testAiCrop() throws Exception { String returnJson = "{\n" + " \"errcode\": 0, \n" + " \"errmsg\": \"ok\", \n" + " \"results\": [ //智能裁剪结果\n" + " {\n" + " \"crop_left\": 112, \n" + " \"crop_top\": 0, \n" + " \"crop_right\": 839, \n" + " \"crop_bottom\": 727\n" + " }, \n" + " {\n" + " \"crop_left\": 0, \n" + " \"crop_top\": 205, \n" + " \"crop_right\": 965, \n" + " \"crop_bottom\": 615\n" + " }\n" + " ], \n" + " \"img_size\": { //图片大小\n" + " \"w\": 966, \n" + " \"h\": 728\n" + " }\n" + "}"; when(wxService.get(anyString(), anyString())).thenReturn(returnJson); final WxImgProcService wxMpImgProcService = new WxMpImgProcServiceImpl(wxService); final WxImgProcAiCropResult result = wxMpImgProcService.aiCrop("abc"); assertThat(result).isNotNull(); System.out.println(result); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideTagServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideTagServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.WxMpGuideBuyerResp; import me.chanjar.weixin.mp.bean.guide.WxMpGuideTagInfo; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://www.sacoc.cn">广州跨界-宋心成</a> * created on 2021/5/13/013 */ @Guice(modules = ApiTestModule.class) public class WxMpGuideTagServiceImplTest { @Inject protected WxMpService wxService; /** * 顾问微信号 guide_account */ private static final String ACCOUNT = "sxc_Warm"; @Test public void testNewGuideTagOption() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("分类一"); list.add("分类二"); list.add("分类三"); this.wxService.getGuideTagService().newGuideTagOption("A组", list); } @Test public void testDelGuideTagOption() throws WxErrorException { this.wxService.getGuideTagService().delGuideTagOption("A组"); } @Test public void testAddGuideTagOption() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("分类四"); this.wxService.getGuideTagService().addGuideTagOption("A组", list); } @Test public void testGetGuideTagOption() throws WxErrorException { List<WxMpGuideTagInfo> guideTagOption = this.wxService.getGuideTagService().getGuideTagOption(); assertThat(guideTagOption).isNotNull(); } @Test public void testAddGuideBuyerTag() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("oqlk8v0uTJgRnn5eEskNruD4-bc8"); list.add("oqlk8vybPMWapMwOfFTFVYqWpGM0"); List<WxMpGuideBuyerResp> wxMpGuideBuyerResps = this.wxService.getGuideTagService().addGuideBuyerTag(ACCOUNT, null, "分类一", list); assertThat(wxMpGuideBuyerResps).isNotNull(); } @Test public void testAddGuideBuyerTagOnce() throws WxErrorException { this.wxService.getGuideTagService().addGuideBuyerTag(ACCOUNT, null, "分类二", "oqlk8v0uTJgRnn5eEskNruD4-bc8"); } @Test public void testGetGuideBuyerTag() throws WxErrorException { List<String> guideBuyerTag = this.wxService.getGuideTagService().getGuideBuyerTag(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8", true); assertThat(guideBuyerTag).isNotNull(); } @Test public void testQueryGuideBuyerByTag() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("分类一"); List<String> list1 = this.wxService.getGuideTagService().queryGuideBuyerByTag(ACCOUNT, null, 0, list); assertThat(list1).isNotNull(); } @Test public void testdelGuideBuyerTag() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("oqlk8v0uTJgRnn5eEskNruD4-bc8"); list.add("oqlk8vybPMWapMwOfFTFVYqWpGM0"); List<WxMpGuideBuyerResp> respList = this.wxService.getGuideTagService().delGuideBuyerTag(ACCOUNT, null, "分类一", list); assertThat(respList).isNotNull(); } @Test public void testDelGuideBuyerTagOnce() throws WxErrorException { this.wxService.getGuideTagService().delGuideBuyerTag(ACCOUNT, null, "分类一", "oqlk8v0uTJgRnn5eEskNruD4-bc8"); } @Test public void testAddGuideBuyerDisplayTag() throws WxErrorException { List<String> list = new ArrayList<>(); list.add("自定义信息1"); list.add("自定义信息2"); this.wxService.getGuideTagService().addGuideBuyerDisplayTag(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8", list); } @Test public void testGetGuideBuyerDisplayTag() throws WxErrorException { List<String> list = this.wxService.getGuideTagService().getGuideBuyerDisplayTag(ACCOUNT, null, "oqlk8v0uTJgRnn5eEskNruD4-bc8"); assertThat(list).isNotNull(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpAiOpenServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import java.io.File; import org.testng.annotations.*; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.enums.AiLangType; import static org.assertj.core.api.Assertions.assertThat; /** * <pre> * Created by BinaryWang on 2018/6/10. * </pre> * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class WxMpAiOpenServiceImplTest { @Inject protected WxMpService wxService; @Test public void testUploadVoice() throws WxErrorException { String voiceId = System.currentTimeMillis() + "a"; AiLangType lang = AiLangType.zh_CN; this.wxService.getAiOpenService().uploadVoice(voiceId, lang, new File("d:\\t.mp3")); } @Test public void testRecogniseVoice() throws WxErrorException { String voiceId = System.currentTimeMillis() + "a"; AiLangType lang = AiLangType.zh_CN; final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3")); assertThat(result).isNotEmpty(); } @Test public void testTranslate() throws WxErrorException { final String result = this.wxService.getAiOpenService().translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹"); assertThat(result).isNotEmpty(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMaterialServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConstants; import me.chanjar.weixin.mp.bean.material.*; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.*; import static org.testng.Assert.*; /** * 素材管理相关接口的测试 * * @author chanjarster * @author codepiano * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMaterialServiceImplTest { @Inject protected WxMpService wxService; private Map<String, Map<String, Object>> mediaIds = new LinkedHashMap<>(); // 缩略图的id,测试上传图文使用 private String thumbMediaId = ""; // 单图文消息media_id private String singleNewsMediaId = ""; // 多图文消息media_id private String multiNewsMediaId = ""; // 先查询保存测试开始前永久素材数据 private WxMpMaterialCountResult wxMaterialCountResultBeforeTest; // 以下为media接口的测试 private List<String> mediaIdsToDownload = new ArrayList<>(); // 以下为高清语音接口的测试 private List<String> voiceMediaIdsToDownload = new ArrayList<>(); @DataProvider public Object[][] mediaFiles() { return new Object[][]{ new Object[]{WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, "mm.jpeg"}, new Object[]{WxConsts.MediaFileType.VOICE, TestConstants.FILE_MP3, "mm.mp3"}, new Object[]{WxConsts.MediaFileType.VIDEO, TestConstants.FILE_MP4, "mm.mp4"}, new Object[]{WxConsts.MediaFileType.THUMB, TestConstants.FILE_JPG, "mm.jpeg"} }; } @Test(dataProvider = "mediaFiles") public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { if (this.wxMaterialCountResultBeforeTest == null) { this.wxMaterialCountResultBeforeTest = this.wxService.getMaterialService() .materialCount(); } try (InputStream inputStream = ClassLoader .getSystemResourceAsStream(fileName)) { File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType); WxMpMaterial wxMaterial = new WxMpMaterial(); wxMaterial.setFile(tempFile); wxMaterial.setName(fileName); if (WxConsts.MediaFileType.VIDEO.equals(mediaType)) { wxMaterial.setVideoTitle("title"); wxMaterial.setVideoIntroduction("test video description"); } WxMpMaterialUploadResult res = this.wxService.getMaterialService() .materialFileUpload(mediaType, wxMaterial); assertNotNull(res.getMediaId()); if (WxConsts.MediaFileType.IMAGE.equals(mediaType) || WxConsts.MediaFileType.THUMB.equals(mediaType)) { assertNotNull(res.getUrl()); } if (WxConsts.MediaFileType.THUMB.equals(mediaType)) { this.thumbMediaId = res.getMediaId(); } Map<String, Object> materialInfo = new HashMap<>(); materialInfo.put("media_id", res.getMediaId()); materialInfo.put("length", tempFile.length()); materialInfo.put("filename", tempFile.getName()); this.mediaIds.put(res.getMediaId(), materialInfo); System.out.println(res); } } @Test(dependsOnMethods = {"testUploadMaterial"}) public void testAddNews() throws WxErrorException { // 单图文消息 WxMpMaterialNews wxMpMaterialNewsSingle = new WxMpMaterialNews(); WxMpNewsArticle article = new WxMpNewsArticle(); article.setAuthor("author"); article.setThumbMediaId(this.thumbMediaId); article.setTitle("single title"); article.setContent("single content"); article.setContentSourceUrl("content url"); article.setShowCoverPic(true); article.setDigest("single news"); wxMpMaterialNewsSingle.addArticle(article); // 多图文消息 WxMpMaterialNews wxMpMaterialNewsMultiple = new WxMpMaterialNews(); WxMpNewsArticle article1 = new WxMpNewsArticle(); article1.setAuthor("author1"); article1.setThumbMediaId(this.thumbMediaId); article1.setTitle("multi title1"); article1.setContent("content 1"); article1.setContentSourceUrl("content url"); article1.setShowCoverPic(true); article1.setDigest(""); WxMpNewsArticle article2 = new WxMpNewsArticle(); article2.setAuthor("author2"); article2.setThumbMediaId(this.thumbMediaId); article2.setTitle("multi title2"); article2.setContent("content 2"); article2.setContentSourceUrl("content url"); article2.setShowCoverPic(true); article2.setDigest(""); wxMpMaterialNewsMultiple.addArticle(article1); wxMpMaterialNewsMultiple.addArticle(article2); } @Test(dependsOnMethods = {"testAddNews"}) public void testMaterialCount() throws WxErrorException { WxMpMaterialCountResult wxMaterialCountResult = this.wxService.getMaterialService().materialCount(); // 测试上传过程中添加了一个音频,一个视频,两个图片,两个图文消息 assertEquals( this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, wxMaterialCountResult.getVoiceCount()); assertEquals( this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, wxMaterialCountResult.getVideoCount()); assertEquals( this.wxMaterialCountResultBeforeTest.getImageCount() + 2, wxMaterialCountResult.getImageCount()); assertEquals(this.wxMaterialCountResultBeforeTest.getNewsCount() + 2, wxMaterialCountResult.getNewsCount()); } @Test(dependsOnMethods = {"testMaterialCount"}, dataProvider = "downloadMaterial") public void testDownloadMaterial(String mediaId) throws WxErrorException, IOException { Map<String, Object> materialInfo = this.mediaIds.get(mediaId); assertNotNull(materialInfo); String filename = materialInfo.get("filename").toString(); if (filename.endsWith(".mp3") || filename.endsWith(".jpeg")) { try (InputStream inputStream = this.wxService.getMaterialService() .materialImageOrVoiceDownload(mediaId)) { assertNotNull(inputStream); } } if (filename.endsWith("mp4")) { WxMpMaterialVideoInfoResult wxMaterialVideoInfoResult = this.wxService.getMaterialService().materialVideoInfo(mediaId); assertNotNull(wxMaterialVideoInfoResult); assertNotNull(wxMaterialVideoInfoResult.getDownUrl()); } } @Test(dependsOnMethods = {"testAddNews", "testUploadMaterial"}) public void testGetNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService .getMaterialService().materialNewsInfo(this.singleNewsMediaId); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertNotNull(wxMpMaterialNewsMultiple); System.out.println(wxMpMaterialNewsSingle); System.out.println(wxMpMaterialNewsMultiple); } @Test(dependsOnMethods = {"testGetNewsInfo"}) public void testUpdateNewsInfo() throws WxErrorException { WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService .getMaterialService().materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); WxMpNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); articleSingle.setContent("content single update"); wxMpMaterialArticleUpdateSingle.setMediaId(this.singleNewsMediaId); wxMpMaterialArticleUpdateSingle.setArticles(articleSingle); wxMpMaterialArticleUpdateSingle.setIndex(0); wxMpMaterialNewsSingle = this.wxService.getMaterialService() .materialNewsInfo(this.singleNewsMediaId); assertNotNull(wxMpMaterialNewsSingle); assertEquals("content single update", wxMpMaterialNewsSingle.getArticles().get(0).getContent()); WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService .getMaterialService().materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); WxMpNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); articleMulti.setContent("content 2 update"); wxMpMaterialArticleUpdateMulti.setMediaId(this.multiNewsMediaId); wxMpMaterialArticleUpdateMulti.setArticles(articleMulti); wxMpMaterialArticleUpdateMulti.setIndex(1); wxMpMaterialNewsMultiple = this.wxService.getMaterialService() .materialNewsInfo(this.multiNewsMediaId); assertNotNull(wxMpMaterialNewsMultiple); assertEquals("content 2 update", wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); } @Test(dependsOnMethods = {"testUpdateNewsInfo"}) public void testMaterialNewsList() throws WxErrorException { WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = this.wxService.getMaterialService().materialNewsBatchGet(0, 20); assertNotNull(wxMpMaterialNewsBatchGetResult); } @Test//(dependsOnMethods = {"testMaterialNewsList"}) public void testMaterialFileList() throws WxErrorException { WxMpMaterialFileBatchGetResult wxMpMaterialVoiceBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.VOICE, 0, 20); WxMpMaterialFileBatchGetResult wxMpMaterialVideoBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.VIDEO, 0, 20); WxMpMaterialFileBatchGetResult wxMpMaterialImageBatchGetResult = this.wxService.getMaterialService().materialFileBatchGet(WxConsts.MaterialType.IMAGE, 0, 20); assertNotNull(wxMpMaterialVoiceBatchGetResult); assertNotNull(wxMpMaterialVideoBatchGetResult); assertNotNull(wxMpMaterialImageBatchGetResult); } @Test(dependsOnMethods = {"testMaterialFileList"}, dataProvider = "allTestMaterial") public void testDeleteMaterial(String mediaId) throws WxErrorException { this.delete(mediaId); } @Test public void testDeleteMaterialDirectly() throws WxErrorException { this.delete("abc"); } public void delete(String mediaId) throws WxErrorException { boolean result = this.wxService.getMaterialService().materialDelete(mediaId); assertTrue(result); } @DataProvider public Object[][] downloadMaterial() { Object[][] params = new Object[this.mediaIds.size()][]; int index = 0; for (String mediaId : this.mediaIds.keySet()) { params[index] = new Object[]{mediaId}; index++; } return params; } @DataProvider public Iterator<Object[]> allTestMaterial() { List<Object[]> params = new ArrayList<>(); for (String mediaId : this.mediaIds.keySet()) { params.add(new Object[]{mediaId}); } params.add(new Object[]{this.singleNewsMediaId}); params.add(new Object[]{this.multiNewsMediaId}); return params.iterator(); } @Test(dataProvider = "mediaFiles") public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)) { WxMediaUploadResult res = this.wxService.getMaterialService().mediaUpload(mediaType, fileType, inputStream); assertNotNull(res.getType()); assertNotNull(res.getCreatedAt()); assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null); if (res.getMediaId() != null && !mediaType.equals(WxConsts.MediaFileType.VIDEO)) { //video 不支持下载,所以不加入 this.mediaIdsToDownload.add(res.getMediaId()); // 音频media, 用于测试下载高清语音接口 if (mediaType.equals(WxConsts.MediaFileType.VOICE)) { this.voiceMediaIdsToDownload.add(res.getMediaId()); } } if (res.getThumbMediaId() != null) { this.mediaIdsToDownload.add(res.getThumbMediaId()); } System.out.println(res); } } @DataProvider public Object[][] downloadMedia() { Object[][] params = new Object[this.mediaIdsToDownload.size()][]; for (int i = 0; i < this.mediaIdsToDownload.size(); i++) { params[i] = new Object[]{this.mediaIdsToDownload.get(i)}; } return params; } @DataProvider public Object[][] downloadJssdkMedia() { Object[][] params = new Object[this.voiceMediaIdsToDownload.size()][]; for (int i = 0; i < this.voiceMediaIdsToDownload.size(); i++) { params[i] = new Object[]{this.voiceMediaIdsToDownload.get(i)}; } return params; } @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia") public void testDownloadMedia(String mediaId) throws WxErrorException { File file = this.wxService.getMaterialService().mediaDownload(mediaId); assertNotNull(file); System.out.println(file.getAbsolutePath()); } @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadJssdkMedia") public void testDownloadJssdkMedia(String mediaId) throws WxErrorException { File file = this.wxService.getMaterialService().jssdkMediaDownload(mediaId); assertNotNull(file); System.out.println(file.getAbsolutePath()); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMapConfigImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMapConfigImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl; import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; /** * 测试 ConcurrentHashMap 保存配置信息 * @author jimmyjimmy-sw */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMapConfigImplTest { @Inject private WxMpService wxService; /** * 测试多租户保存 WxMpMapConfigImpl 到 WxMpService,切换之后能获取到租户各自AppId对应的token * @throws WxErrorException */ @Test public void testAppidSwitch() throws WxErrorException { // 保存租户A的配置信息,并获取token WxMpMapConfigImpl configAppA = new WxMpMapConfigImpl(); String appidA = "APPID_A"; configAppA.setAppId(appidA); configAppA.setSecret("APP_SECRET_A"); configAppA.useStableAccessToken(true); String tokenA = "TOKEN_A"; configAppA.updateAccessToken(tokenA,60 * 60 * 1); wxService.addConfigStorage(appidA, configAppA); WxMpConfigStorageHolder.set(appidA); assertEquals(this.wxService.getAccessToken(),tokenA); // 保存租户B的配置信息,并获取token WxMpMapConfigImpl configAppB = new WxMpMapConfigImpl(); String appidB = "APPID_B"; configAppB.setAppId(appidB); configAppB.setSecret("APP_SECRET_B"); configAppB.useStableAccessToken(true); String tokenB = "TOKEN_B"; configAppB.updateAccessToken(tokenB,60 * 60 * 1); wxService.addConfigStorage(appidB, configAppB); WxMpConfigStorageHolder.set(appidB); assertEquals(this.wxService.getAccessToken(),tokenB); // 上下文切换到租户A 获取租户A的token WxMpConfigStorageHolder.set(appidA); assertEquals(this.wxService.getAccessToken(),tokenA); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideMassedJobServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideMassedJobServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.WxMpGuideMassed; import me.chanjar.weixin.mp.bean.guide.WxMpGuideMassedInfo; import me.chanjar.weixin.mp.bean.guide.WxMpGuideMaterialInfo; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://www.sacoc.cn">广州跨界-宋心成</a> * created on 2021/5/13/013 */ @Guice(modules = ApiTestModule.class) public class WxMpGuideMassedJobServiceImplTest { @Inject protected WxMpService wxService; /** * 顾问微信号 guide_account */ private static final String ACCOUNT = "sxc_Warm"; @Test public void testAddGuideMassedJob() throws WxErrorException { List<String> userOpenId = new ArrayList<>(); userOpenId.add("oqlk8v0uTJgRnn5eEskNruD4-bc8"); List<WxMpGuideMaterialInfo> list = new ArrayList<>(); list.add(WxMpGuideMaterialInfo.builder().type(1).word("文字素材测试").build()); list.add(WxMpGuideMaterialInfo.builder().type(3).mediaId("qDrCfXeDorLgy83d8h6VzVip9s6omPXF_2ILuoke1j0sY4bSFVaA8lkGzUaznU9e").build()); //图片素材 list.add(WxMpGuideMaterialInfo.builder().type(49).mediaId("qDrCfXeDorLgy83d8h6VzVip9s6omPXF_2ILuoke1j0sY4bSFVaA8lkGzUaznU9e").title("小程序标题").path("pages/login-type/index.html").appId("wx4f793c04fd3be5a8").build()); //图片素材 WxMpGuideMassed wxMpGuideMassed = this.wxService.getGuideMassedJobService().addGuideMassedJob(ACCOUNT, null, "群发任务", "群发任务备注", System.currentTimeMillis() / 1000, userOpenId, list); assertThat(wxMpGuideMassed).isNotNull(); } @Test public void testGetGuideMassedJobList() throws WxErrorException { List<WxMpGuideMassedInfo> guideMassedJobList = this.wxService.getGuideMassedJobService().getGuideMassedJobList(ACCOUNT, null, null, null, null); assertThat(guideMassedJobList).isNotNull(); } @Test public void testGetGuideMassedJob() throws WxErrorException { WxMpGuideMassedInfo guideMassedJob = this.wxService.getGuideMassedJobService().getGuideMassedJob("1867407932930228228"); assertThat(guideMassedJob).isNotNull(); } @Test public void testUpdateGuideMassedJob() throws WxErrorException { this.wxService.getGuideMassedJobService().updateGuideMassedJob("1867407932930228228", "修改群发任务", null, null, null, null); } @Test public void testCancelGuideMassedJob() throws WxErrorException { this.wxService.getGuideMassedJobService().cancelGuideMassedJob("1867407932930228228"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMarketingServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMarketingServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.common.collect.Lists; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 测试类. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-07-14 */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMarketingServiceImplTest { @Inject protected WxMpService wxService; @Test public void testAddUserActionSets() { } @Test public void testGetUserActionSets() { } @Test public void testAddUserAction() throws WxErrorException { this.wxService.getMarketingService().addUserAction(Lists.newArrayList(new WxMpUserAction())); } @Test public void testGetAdLeads() { } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid; import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUserList; import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static me.chanjar.weixin.mp.enums.WxMpApiUrl.User.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * 测试用户相关的接口 * * @author chanjarster * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) public class WxMpUserServiceImplTest { @Inject private WxMpService wxService; private TestConfigStorage configProvider; @BeforeTest public void setup() { this.configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); } public void testUserUpdateRemark() throws WxErrorException { this.wxService.getUserService() .userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); } public void testUserInfo() throws WxErrorException { WxMpUser user = this.wxService.getUserService() .userInfo(this.configProvider.getOpenid(), null); Assert.assertNotNull(user); System.out.println(user); } public void testUserInfoList() throws WxErrorException { List<String> openids = new ArrayList<>(); openids.add(this.configProvider.getOpenid()); List<WxMpUser> userList = this.wxService.getUserService() .userInfoList(openids); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } public void testUserInfoListByWxMpUserQuery() throws WxErrorException { WxMpUserQuery query = new WxMpUserQuery(); query.add(this.configProvider.getOpenid(), "zh_CN"); List<WxMpUser> userList = this.wxService.getUserService() .userInfoList(query); Assert.assertEquals(userList.size(), 1); System.out.println(userList); } public void testUserList() throws WxErrorException { WxMpUserList wxMpUserList = this.wxService.getUserService().userList(null); Assert.assertNotNull(wxMpUserList); Assert.assertNotEquals(-1, wxMpUserList.getCount()); Assert.assertNotEquals(-1, wxMpUserList.getTotal()); Assert.assertNotEquals(-1, wxMpUserList.getOpenids().size()); System.out.println(wxMpUserList); } public void testChangeOpenid() throws WxErrorException { List<String> openids = new ArrayList<>(); openids.add(this.configProvider.getOpenid()); List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid("原公众号appid", openids); Assert.assertNotNull(wxMpChangeOpenidList); Assert.assertEquals(1, wxMpChangeOpenidList.size()); WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); Assert.assertNotNull(wxMpChangeOpenid); Assert.assertEquals(this.configProvider.getOpenid(), wxMpChangeOpenid.getOriOpenid()); System.out.println(wxMpChangeOpenid); } public static class MockTest { private WxMpService wxService = mock(WxMpService.class); @Test public void testMockChangeOpenid() throws WxErrorException { List<String> openids = new ArrayList<>(); openids.add("oEmYbwN-n24jxvk4Sox81qedINkQ"); openids.add("oEmYbwH9uVd4RKJk7ZZg6SzL6tTo"); String fromAppid = "old_appid"; Map<String, Object> map = new HashMap<>(); map.put("from_appid", fromAppid); map.put("openid_list", openids); String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"result_list\": [{\"ori_openid\": \"oEmYbwN-n24jxvk4Sox81qedINkQ\",\"new_openid\": \"o2FwqwI9xCsVadFah_HtpPfaR-X4\",\"err_msg\": \"ok\"},{\"ori_openid\": \"oEmYbwH9uVd4RKJk7ZZg6SzL6tTo\",\"err_msg\": \"ori_openid error\"}]}"; when(wxService.post(USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map))).thenReturn(returnJson); List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid(fromAppid, openids); Assert.assertNotNull(wxMpChangeOpenidList); Assert.assertEquals(2, wxMpChangeOpenidList.size()); WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0); Assert.assertNotNull(wxMpChangeOpenid); Assert.assertEquals("oEmYbwN-n24jxvk4Sox81qedINkQ", wxMpChangeOpenid.getOriOpenid()); Assert.assertEquals("o2FwqwI9xCsVadFah_HtpPfaR-X4", wxMpChangeOpenid.getNewOpenid()); Assert.assertEquals("ok", wxMpChangeOpenid.getErrMsg()); wxMpChangeOpenid = wxMpChangeOpenidList.get(1); Assert.assertNotNull(wxMpChangeOpenid); Assert.assertEquals("oEmYbwH9uVd4RKJk7ZZg6SzL6tTo", wxMpChangeOpenid.getOriOpenid()); Assert.assertNull(wxMpChangeOpenid.getNewOpenid()); Assert.assertEquals("ori_openid error", wxMpChangeOpenid.getErrMsg()); System.out.println(wxMpChangeOpenid); } } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; import org.testng.annotations.Guice; import org.testng.annotations.Test; /** * 测试摇一摇周边相关的接口 * * @author rememberber */ @Test(groups = "userAPI") @Guice(modules = ApiTestModule.class) public class WxMpShakeServiceImplTest { @Inject private WxMpService wxService; public void testGetShakeInfo() throws Exception { WxMpShakeQuery wxMpShakeQuery = new WxMpShakeQuery(); wxMpShakeQuery.setTicket("b87db7df490e5cbe4f598272f77f46be"); wxMpShakeQuery.setNeedPoi(1); WxMpShakeInfoResult wxMpShakeInfoResult = this.wxService.getShakeService().getShakeInfo(wxMpShakeQuery); System.out.println(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpCommentService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.comment.WxMpCommentListVo; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; /** * 测试类. * * @author <a href="https://github.com/binarywang">Binary Wang</a> * created on 2019-06-16 */ @Test @Guice(modules = ApiTestModule.class) public class WxMpCommentServiceImplTest { @Inject private WxMpService wxService; @Test public void testOpen() throws WxErrorException { this.wxService.getCommentService().open("1", null); this.wxService.getCommentService().open("1", 0); } @Test public void testClose() throws WxErrorException { this.wxService.getCommentService().close("1000000001", null); this.wxService.getCommentService().close("1", 0); } @Test public void testList() throws WxErrorException { String expectedResponse = "{\n" + " \"errcode\": 0,\n" + " \"errmsg\": \"ok\",\n" + " \"total\": 1,\n" + " \"comment\": [\n" + " {\n" + " \"user_comment_id\": 1,\n" + " \"openid\": \"OPENID\",\n" + " \"create_time\": \"CREATE_TIME\",\n" + " \"content\": \"CONTENT\",\n" + " \"comment_type\": 1,\n" + " \"reply\": {\n" + " \"content\": \"CONTENT\",\n" + " \"create_time\": \"CREATE_TIME\"\n" + " }\n" + " }\n" + " ]\n" + "}"; wxService = spy(wxService); WxMpCommentService commentService = new WxMpCommentServiceImpl(wxService); doReturn(expectedResponse).when(wxService).post(anyString(), anyString()); final WxMpCommentListVo commentListVo = commentService.list("1", 1, 1, 1, 1); assertThat(commentListVo).isNotNull(); System.out.println(commentListVo); assertThat(commentListVo.getTotal()).isEqualTo(1); assertThat(commentListVo.getComment()).isNotEmpty(); assertThat(commentListVo.getComment().get(0).getReply()).isNotNull(); } @Test public void testMarkElect() throws WxErrorException { this.wxService.getCommentService().markElect("1000000001", null, 1L); } @Test public void testUnmarkElect() throws WxErrorException { this.wxService.getCommentService().unmarkElect("1000000001", null, 1L); } @Test public void testDelete() throws WxErrorException { this.wxService.getCommentService().delete("1000000001", null, 1L); } @Test public void testReplyAdd() throws WxErrorException { this.wxService.getCommentService().replyAdd("1000000001", null, 1L, "haha"); } @Test public void testReplyADelete() throws WxErrorException { this.wxService.getCommentService().replyDelete("1000000001", null, 1L); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.testng.Assert.assertNotNull; /** * 测试菜单 * * @author chanjarster * @author Binary Wang */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMenuServiceImplTest { @Inject protected WxMpService wxService; private String menuId = null; @Test(dataProvider = "menu") public void testMenuCreate(WxMenu wxMenu) throws WxErrorException { System.out.println(wxMenu.toJson()); this.wxService.getMenuService().menuCreate(wxMenu); } @Test public void testMenuTryMatch() throws Exception { WxMenu menu = this.wxService.getMenuService().menuTryMatch("..."); System.out.println(menu); } @Test public void testGetSelfMenuInfo() throws Exception { WxMpGetSelfMenuInfoResult selfMenuInfo = this.wxService.getMenuService().getSelfMenuInfo(); System.out.println(selfMenuInfo); } @Test public void testCreateConditionalMenu() throws WxErrorException { String json = "{\n" + " \"button\":[\n" + " { \n" + " \"type\":\"click\",\n" + " \"name\":\"今日歌曲\",\n" + " \"key\":\"V1001_TODAY_MUSIC\" \n" + " },\n" + " { \n" + " \"name\":\"菜单\",\n" + " \"sub_button\":[\n" + " { \n" + " \"type\":\"view\",\n" + " \"name\":\"搜索\",\n" + " \"url\":\"http://www.soso.com/\"\n" + " },\n" + " {\n" + " \"type\":\"view\",\n" + " \"name\":\"视频\",\n" + " \"url\":\"http://v.qq.com/\"\n" + " },\n" + " {\n" + " \"type\":\"click\",\n" + " \"name\":\"赞一下我们\",\n" + " \"key\":\"V1001_GOOD\"\n" + " }]\n" + " }],\n" + "\"matchrule\":{\n" + " \"tag_id\":\"2\",\n" + " \"sex\":\"1\",\n" + " \"country\":\"中国\",\n" + " \"province\":\"广东\",\n" + " \"city\":\"广州\",\n" + " \"client_platform_type\":\"2\",\n" + " \"language\":\"zh_CN\"\n" + " }\n" + "}"; this.menuId = this.wxService.getMenuService().menuCreate(json); System.out.println(this.menuId); } @Test public void testMultiCreateConditionalMenu() throws WxErrorException { String json = "{\n" + " \"button\":[\n" + " { \n" + " \"type\":\"click\",\n" + " \"name\":\"今日歌曲\",\n" + " \"key\":\"V1001_TODAY_MUSIC\" \n" + " },\n" + " { \n" + " \"name\":\"菜单\",\n" + " \"sub_button\":[\n" + " { \n" + " \"type\":\"view\",\n" + " \"name\":\"搜索\",\n" + " \"url\":\"http://www.soso.com/\"\n" + " },\n" + " {\n" + " \"type\":\"view\",\n" + " \"name\":\"视频\",\n" + " \"url\":\"http://v.qq.com/\"\n" + " },\n" + " {\n" + " \"type\":\"click\",\n" + " \"name\":\"赞一下我们\",\n" + " \"key\":\"V1001_GOOD\"\n" + " }]\n" + " }],\n" + "\"matchrule\":{\n" + " \"tag_id\":\"2\",\n" + " \"sex\":\"1\",\n" + " \"country\":\"中国\",\n" + " \"province\":\"广东\",\n" + " \"city\":\"广州\",\n" + " \"client_platform_type\":\"2\",\n" + " \"language\":\"zh_CN\"\n" + " }\n" + "}"; this.menuId = this.wxService.getMenuService().menuCreate(json); System.out.println(this.menuId); } @Test(dependsOnMethods = {"testCreateConditionalMenu"}) public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException { WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); assertNotNull(wxMenu); System.out.println(wxMenu.toJson()); assertNotNull(wxMenu.getConditionalMenu().get(0).getRule().getTagId()); } @Test(dependsOnMethods = {"testCreateConditionalMenu"}) public void testDeleteConditionalMenu() throws WxErrorException { this.wxService.getMenuService().menuDelete(menuId); } @Test public void testCreateMenu_by_json() throws WxErrorException { String a = "{\n" + " \"button\": [\n" + " {\n" + " \"type\": \"click\",\n" + " \"name\": \"今日歌曲\",\n" + " \"key\": \"V1001_TODAY_MUSIC\"\n" + " },\n" + " {\n" + " \"name\": \"菜单\",\n" + " \"sub_button\": [\n" + " {\n" + " \"type\": \"view\",\n" + " \"name\": \"搜索\",\n" + " \"url\": \"http://www.soso.com/\"\n" + " },\n" + " {\n" + " \"type\": \"miniprogram\",\n" + " \"name\": \"wxa\",\n" + " \"url\": \"http://mp.weixin.qq.com\",\n" + " \"appid\": \"wx286b93c14bbf93aa\",\n" + " \"pagepath\": \"pages/lunar/index.html\"\n" + " },\n" + " {\n" + " \"type\": \"click\",\n" + " \"name\": \"赞一下我们\",\n" + " \"key\": \"V1001_GOOD\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"; WxMenu menu = WxMenu.fromJson(a); System.out.println(menu.toJson()); this.wxService.getMenuService().menuCreate(menu); } @Test(dependsOnMethods = {"testMenuCreate"}) public void testMenuGet() throws WxErrorException { WxMpMenu wxMenu = this.wxService.getMenuService().menuGet(); assertNotNull(wxMenu); System.out.println(wxMenu.toJson()); } @Test(dependsOnMethods = {"testMenuGet", "testMenuCreate"}) public void testMenuDelete() throws WxErrorException { this.wxService.getMenuService().menuDelete(); } @DataProvider(name = "menu") public Object[][] getMenu() { WxMenu menu = new WxMenu(); WxMenuButton button1 = new WxMenuButton(); button1.setType(WxConsts.MenuButtonType.CLICK); button1.setName("今日歌曲"); button1.setKey("V1001_TODAY_MUSIC"); // WxMenuButton button2 = new WxMenuButton(); // button2.setType(WxConsts.MenuButtonType.MINIPROGRAM); // button2.setName("小程序"); // button2.setAppId("wx286b93c14bbf93aa"); // button2.setPagePath("pages/lunar/index.html"); // button2.setUrl("http://mp.weixin.qq.com"); WxMenuButton button3 = new WxMenuButton(); button3.setName("菜单"); menu.getButtons().add(button1); // menu.getButtons().add(button2); menu.getButtons().add(button3); WxMenuButton button31 = new WxMenuButton(); button31.setType(WxConsts.MenuButtonType.VIEW); button31.setName("搜索"); button31.setUrl("http://www.soso.com/"); WxMenuButton button32 = new WxMenuButton(); button32.setType(WxConsts.MenuButtonType.VIEW); button32.setName("视频"); button32.setUrl("http://v.qq.com/"); WxMenuButton button33 = new WxMenuButton(); button33.setType(WxConsts.MenuButtonType.CLICK); button33.setName("赞一下我们"); button33.setKey("V1001_GOOD"); button3.getSubButtons().add(button31); button3.getSubButtons().add(button32); button3.getSubButtons().add(button33); return new Object[][]{ new Object[]{ menu } }; } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpFreePublishServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpFreePublishServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishInfo; import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishList; import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishStatus; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; /** * 发布能力-单元测试. * * @author dragon * created on 2021-10-23 */ @Guice(modules = ApiTestModule.class) public class WxMpFreePublishServiceImplTest { /** * 新增草稿后返回的id,发布需要使用 */ final String mediaId = "HKVdzjkDfooMqBqJtvSs2EEeRAJaM33gJgkii_JDOHg"; /** * 发布后的id,后续查询等需要使用 */ final String publishId = "2650177669"; /** * 图文的 article_id,后续查询图文详情、删除发布内容 需要使用 * 要根据 publishId 来获取 article_id * * @see this.testGetPushStatus */ final String articleId = "zjMKVd1g66BkEkpetwml4ElbDdniE8JeI2Ec324Sjqg"; @Inject protected WxMpService wxService; @Test public void testSubmit() throws WxErrorException { String submit = this.wxService.getFreePublishService().submit(mediaId); assertThat(submit).isNotBlank(); // 【响应数据】:{"errcode":0,"errmsg":"ok","publish_id":2650177668} } @Test public void testGetPushStatus() throws WxErrorException { WxMpFreePublishStatus pushStatus = this.wxService.getFreePublishService().getPushStatus(publishId); assertThat(pushStatus).isNotNull(); // 【响应数据】:{"publish_id":2650177668,"publish_status":0,"article_id":"zjMKVd1g66BkEkpetwml4J-4gNf4I1nsh-B-r_inemw", // "article_detail":{"count":1,"item": // [{"idx":1,"article_url": // "https://mp.weixin.qq.com/s?__biz=MzAwMTE2MzA1xxxxxxxxxx" // }]},"fail_idx":[]} // article_url -> 已发布内容可被自定义菜单、自动回复、话题引用,也可用于公开传播 } @Test public void testGetArticleFromId() throws WxErrorException { WxMpFreePublishInfo articleFromId = this.wxService.getFreePublishService().getArticleFromId(articleId); assertThat(articleFromId).isNotNull(); /* 【响应数据】:{"news_item":[{"title":"欢迎你加入啊~ 这是我的第一条文字消息草稿","author":"","digest":"","content":"欢迎你加入啊~ 这是我的第一条文字消息草稿", "content_source_url":"","thumb_media_id":"","show_cover_pic":0,"url":"http:\/\/mp.weixin.qq .com\/s?__biz=MzAwMTE2MzA1Mg==&mid=2650177668","thumb_url":"","need_open_comment":1,"only_fans_can_comment":1,"is_deleted":false}], "create_time":1634961670,"update_time":1634961672} */ } @Test public void testDelPush() throws WxErrorException { Boolean deletePush = this.wxService.getFreePublishService().deletePush(articleId, 0); // 【响应数据】:{"errcode":0,"errmsg":"ok"} assertThat(deletePush).isTrue(); } @Test public void testDeletePushAllArticle() throws WxErrorException { Boolean deletePush = this.wxService.getFreePublishService().deletePushAllArticle(articleId); // 【响应数据】:{"errcode":0,"errmsg":"ok"} assertThat(deletePush).isTrue(); } @Test public void testGetPublicationRecords() throws WxErrorException { WxMpFreePublishList publicationRecords = this.wxService.getFreePublishService().getPublicationRecords(0, 10, 0); /* 【响应数据】: {"item":[{"article_id":"zjMKVd1g66BkEkpetwml4BOSzatuEYNY3TFhCc0kSIE","content":{"news_item":[ {"title":"新建草稿-对象形式","author":"dragon","digest":"图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空", "content":"图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS", "content_source_url":"https:\/\/github.com\/Wechat-Group\/WxJava","thumb_media_id":"HKVdzjkDfooMqBqJtvSs2Ajz2v6L_vtGhyyr_mqKcPU", "show_cover_pic":1,"url":"http:\/\/mp.weixin.qq.com\/s?__biz=MzAwMTE2MzA1Mg==&mid=26501776710e5adb91#rd", "thumb_url":"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/0QSAUfroWrUmxHthQ\/0?wx_fmt=jpeg", "need_open_comment":1,"only_fans_can_comment":0,"is_deleted":false}], "create_time":1634976306,"update_time":1634976318}} ] ,"total_count":1,"item_count":1} */ assertThat(publicationRecords).isNotNull(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpUserTagServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxUserTag; import org.testng.*; import org.testng.annotations.*; import java.util.List; /** * Created by Binary Wang on 2016/9/2. * * @author <a href="https://github.com/binarywang">Binary Wang</a> */ @Test @Guice(modules = ApiTestModule.class) public class WxMpUserTagServiceImplTest { @Inject protected WxMpService wxService; private Long tagId = 2L; @Test public void testTagCreate() throws Exception { String tagName = "测试标签" + System.currentTimeMillis(); WxUserTag res = this.wxService.getUserTagService().tagCreate(tagName); System.out.println(res); this.tagId = res.getId(); Assert.assertEquals(tagName, res.getName()); } @Test public void testTagGet() throws Exception { List<WxUserTag> res = this.wxService.getUserTagService().tagGet(); System.out.println(res); Assert.assertNotNull(res); } @Test(dependsOnMethods = {"testTagCreate"}) public void testTagUpdate() throws Exception { String tagName = "修改标签" + System.currentTimeMillis(); Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); System.out.println(res); Assert.assertTrue(res); } @Test(dependsOnMethods = {"testTagCreate"}) public void testTagDelete() throws Exception { Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); System.out.println(res); Assert.assertTrue(res); } @Test public void testTagListUser() throws Exception { WxTagListUser res = this.wxService.getUserTagService().tagListUser(this.tagId, null); System.out.println(res); Assert.assertNotNull(res); } @Test public void testBatchTagging() throws Exception { String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); } @Test public void testBatchUntagging() throws Exception { String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids); System.out.println(res); Assert.assertTrue(res); } @Test public void testUserTagList() throws Exception { List<Long> res = this.wxService.getUserTagService().userTagList( ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); System.out.println(res); Assert.assertNotNull(res); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMemberCardServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.mp.api.WxMpCardService; import me.chanjar.weixin.mp.api.WxMpMemberCardService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.card.*; import me.chanjar.weixin.mp.bean.card.enums.CardSceneType; import me.chanjar.weixin.mp.bean.card.membercard.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import static org.testng.AssertJUnit.assertNotNull; /** * 会员卡相关接口的测试类。 * 数据均为测试数据,由于直接与调用微信的接口,需要填写真实数据进行测试才能通过。 */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMemberCardServiceImplTest { @Inject protected WxMpService wxService; private String cardId = "p4p-v1bKn9tiQHxyO79aKmuTIZlQ"; private String code = "224765120681"; private String openId = "o4p-v1TIemEIpBSrSrTprkCaG6Xc"; @Test public void createMemberCard() throws Exception { // String json = "{\"card\":{\"card_type\":\"MEMBER_CARD\",\"member_card\":{\"advanced_info\":{\"business_service\":\"BIZ_SERVICE_FREE_PARK,BIZ_SERVICE_WITH_PET,BIZ_SERVICE_FREE_WIFI\",\"text_image_list\":[{\"image_url\":\"http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGkENppDhyqhR8bz5BiaJkPT7e6bPVcfBx5cAOLro2N3U989n8WJltkjQ/0\",\"text\":\"8月8日随机免单\"}]},\"auto_activate\":false,\"background_pic_url\":\"http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0\",\"base_info\":{\"bind_openid\":false,\"brand_name\":\"商户名称\",\"can_give_friend\":false,\"can_share\":false,\"center_sub_title\":\"点击进入\",\"center_title\":\"商城首页\",\"center_url\":\"http://www.baidu.com\",\"code_type\":\"CODE_TYPE_QRCODE\",\"color\":\"Color090\",\"date_info\":{\"type\":\"DATE_TYPE_PERMANENT\"},\"description\":\"使用须知\",\"need_push_on_view\":false,\"notice\":\"测试会员卡\",\"service_phone\":\"4008803016\",\"title\":\"终生铂金卡\",\"use_all_locations\":true,\"use_custom_code\":false},\"prerogative\":\"享有特权说明\",\"supply_balance\":true,\"supply_bonus\":true,\"wx_activate\":false}}}"; // WxMpMemberCardCreateMessage createMessage = WxMpMemberCardCreateMessage.fromJson(json); //基本卡券创建 WxMpMemberCardCreateMessage createMessage = new WxMpMemberCardCreateMessage(); MemberCardCreateRequest cardCreateRequest = new MemberCardCreateRequest(); MemberCard memberCard = new MemberCard(); memberCard.setPrerogative("特权说明"); //激活方式 memberCard.setAutoActivate(true);//自动激活 // memberCard.setActivateUrl("http://www.qq.com"); // memberCard.setWxActivate(false);//微信激活 memberCard.setSupplyBonus(true); memberCard.setSupplyBalance(false); memberCard.setBackgroundPicUrl("http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0"); memberCard.setDiscount(0); BaseInfo baseInfo = new BaseInfo(); baseInfo.setLogoUrl("http://wx.qlogo.cn/mmopen/A6hCic476picOEWOJ7NsL7uWhRuh1LibrMC6byhCO6TV1lelyK9iaXbn8nAgFREibPJQTWDeKpicePt88ZHRc8wuicEM0qOllsMXic6O/0"); baseInfo.setCodeType("CODE_TYPE_QRCODE"); baseInfo.setBrandName("信舟科技"); baseInfo.setTitle("铂金用户贵宾卡"); baseInfo.setColor("Color010"); baseInfo.setNotice("卡券使用提醒"); baseInfo.setDescription("卡券使用说明"); baseInfo.setServicePhone("4008803016"); //商品信息 Sku sku = new Sku(); baseInfo.setSku(sku); //使用日期 DateInfo dateInfo = new DateInfo(); baseInfo.setDateInfo(dateInfo); memberCard.setBaseInfo(baseInfo); cardCreateRequest.setMemberCard(memberCard); createMessage.setCardCreateRequest(cardCreateRequest); WxMpCardCreateResult response = this.wxService.getMemberCardService().createMemberCard(createMessage); assertNotNull(response); System.out.println(response); } @Test public void testActivateMemberCard() throws Exception { WxMpMemberCardActivatedMessage activatedMessage = new WxMpMemberCardActivatedMessage(); activatedMessage.setMembershipNumber(openId); // activatedMessage.setCode(code); activatedMessage.setCardId(cardId); activatedMessage.setInitBonus(2000); activatedMessage.setInitBonusRecord("测试激活送积分"); String response = this.wxService.getMemberCardService().activateMemberCard(activatedMessage); assertNotNull(response); System.out.println(response); } @Test public void testGetUserInfo() throws Exception { WxMpMemberCardUserInfoResult result = this.wxService.getMemberCardService().getUserInfo(cardId, code); assertNotNull(result); System.out.println(result); } @Test public void testUpdateUserMemberCard() throws Exception { WxMpMemberCardUpdateMessage updateMessage = new WxMpMemberCardUpdateMessage(); updateMessage.setBonus(1000); updateMessage.setCardId(cardId); updateMessage.setCode(code); WxMpMemberCardUpdateResult result = this.wxService.getMemberCardService().updateUserMemberCard(updateMessage); assertNotNull(result); System.out.println(result); } /** * 测试添加测试openid白名单 * * @throws Exception */ @Test public void testAddTestWhiteList() throws Exception { WxMpCardService cardService = this.wxService.getCardService(); String response = cardService.addTestWhiteList(openId); System.out.println(response); } /** * 测试创建会员卡投放二维码 * * @throws Exception */ @Test public void testCreateQrcodeMemberCard() throws Exception { WxMpCardService cardService = this.wxService.getCardService(); WxMpCardQrcodeCreateResult response = cardService.createQrcodeCard(cardId, "test"); System.out.println(response); } /** * 测试创建货架接口 * * @throws Exception */ @Test public void testCreateLandingPage() throws Exception { WxMpCardService cardService = this.wxService.getCardService(); WxMpCardLandingPageCreateRequest request = new WxMpCardLandingPageCreateRequest(); request.setBanner("http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0"); request.setTitle("会员卡1"); request.setScene(CardSceneType.SCENE_H5.name()); request.addCard(cardId, "http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0"); WxMpCardLandingPageCreateResult response = cardService.createLandingPage(request); System.out.println(response); } @Test public void testGetActivateUrl() throws Exception { WxMpMemberCardService memberCardService = this.wxService.getMemberCardService(); ActivatePluginParam response = memberCardService.getActivatePluginParam(cardId, "test"); System.out.println(response); } @Test public void testGetActivateTempInfo() throws Exception { String activateTicket = "fDZv9eMQAFfrNr3XBoqhb8eUX67DFb6h8yXDelGSMDLfg2OAIGQcU7mEKecnWZBK%2B%2Bvm%2FtZxZJrbRkdJB%2FUmpVoJkEsbeH%2BOefcntAsYDKA%3D"; WxMpMemberCardService memberCardService = this.wxService.getMemberCardService(); WxMpMemberCardActivateTempInfoResult result = memberCardService.getActivateTempInfo(activateTicket); assertNotNull(result); System.out.println(result); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpReimburseInvoiceServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpReimburseInvoiceServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.gson.GsonBuilder; import com.google.inject.Inject; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.invoice.reimburse.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; @Slf4j @Test(groups = "invoiceAPI") @Guice(modules = ApiTestModule.class) public class WxMpReimburseInvoiceServiceImplTest { @Inject protected WxMpService wxService; public void getInvoiceInfo() throws WxErrorException { InvoiceInfoRequest request = InvoiceInfoRequest.builder() .cardId("pnAsy0sHQukID3E8d2IUdh2DbzZ4") .encryptCode("O/mPnGTpBu22a1szmK2ogzhFPBh9eYzv2p70L8yzyynlTOEE9fSC4PXvOGuLIWfqZQXA0yBPVcbELCLySWjiLH0RYjMqE4S2bekki6Z2VUjWHGp+shbOkYZ4y9zR4SpGVT6Dyha0ezDMVw6dFMatoA==") .build(); InvoiceInfoResponse response = this.wxService.getReimburseInvoiceService().getInvoiceInfo(request); log.info("response: {}", new GsonBuilder().create().toJson(response)); } public void getInvoiceBatch() throws WxErrorException { List<InvoiceInfoRequest> invoices = new ArrayList<>(); InvoiceInfoRequest r = InvoiceInfoRequest.builder() .cardId("pnAsy0sHQukID3E8d2IUdh2DbzZ4") .encryptCode("O/mPnGTpBu22a1szmK2ogzhFPBh9eYzv2p70L8yzyynlTOEE9fSC4PXvOGuLIWfqZQXA0yBPVcbELCLySWjiLH0RYjMqE4S2bekki6Z2VUjWHGp+shbOkYZ4y9zR4SpGVT6Dyha0ezDMVw6dFMatoA==") .build(); invoices.add(r); r = InvoiceInfoRequest.builder() .cardId("pnAsy0sHQukID3E8d2IUdh2DbzZ4") .encryptCode("O/mPnGTpBu22a1szmK2ogzhFPBh9eYzv2p70L8yzyynlTOEE9fSC4PXvOGuLIWfqd+8BRcn/yz1GmRwW4LAccaL/dRsSc9RWXektgTHKnoHWHGp+shbOkYZ4y9zR4SpGVT6Dyha0ezDMVw6dFMatoA==") .build(); invoices.add(r); InvoiceBatchRequest request = InvoiceBatchRequest.builder().itemList(invoices).build(); List<InvoiceInfoResponse> responses = this.wxService.getReimburseInvoiceService().getInvoiceBatch(request); log.info("responses: {}",new GsonBuilder().create().toJson(responses)); } public void updateInvoiceStatus() throws WxErrorException { UpdateInvoiceStatusRequest request = UpdateInvoiceStatusRequest.builder() .cardId("**************") .encryptCode("**************") .reimburseStatus("INVOICE_REIMBURSE_INIT") .build(); this.wxService.getReimburseInvoiceService().updateInvoiceStatus(request); } public void updateStatusBatch() throws WxErrorException { List<InvoiceInfoRequest> invoices = new ArrayList<>(); InvoiceInfoRequest r = InvoiceInfoRequest.builder() .cardId("**************") .encryptCode("**************") .build(); invoices.add(r); UpdateStatusBatchRequest request = UpdateStatusBatchRequest.builder() .invoiceList(invoices) .openid("**************") .reimburseStatus("INVOICE_REIMBURSE_INIT") .build(); this.wxService.getReimburseInvoiceService().updateStatusBatch(request); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideMaterialServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideMaterialServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.WxMpGuideCardMaterialInfo; import me.chanjar.weixin.mp.bean.guide.WxMpGuideImgMaterialInfoList; import me.chanjar.weixin.mp.bean.guide.WxMpGuideWordMaterialInfoList; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.io.File; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * @author <a href="https://www.sacoc.cn">广州跨界-宋心成</a> * created on 2021/5/13/013 */ @Guice(modules = ApiTestModule.class) public class WxMpGuideMaterialServiceImplTest { @Inject protected WxMpService wxService; /** * 图片路径 */ private static final String IMG_URL = "C:\\Users\\Administrator\\Desktop\\imgText.png"; @Test public void testSetGuideCardMaterial() throws WxErrorException { WxMediaUploadResult wxMediaUploadResult = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.IMAGE, new File(IMG_URL)); this.wxService.getGuideMaterialService().setGuideCardMaterial(wxMediaUploadResult.getMediaId(), 0, "小程序素材标题", "pages/login-type/index.html", "wx4f793c04fd3be5a8"); } @Test public void testGetGuideCardMaterial() throws WxErrorException { List<WxMpGuideCardMaterialInfo> guideCardMaterial = this.wxService.getGuideMaterialService().getGuideCardMaterial(0); assertThat(guideCardMaterial).isNotNull(); } @Test public void testDelGuideCardMaterial() throws WxErrorException { this.wxService.getGuideMaterialService().delGuideCardMaterial(0, "小程序素材标题", "pages/login-type/index.html", "wx4f793c04fd3be5a8"); } @Test public void testSetGuideImageMaterial() throws WxErrorException { WxMediaUploadResult wxMediaUploadResult = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.IMAGE, new File(IMG_URL)); this.wxService.getGuideMaterialService().setGuideImageMaterial(wxMediaUploadResult.getMediaId(), 0); } @Test public void testGetGuideImageMaterial() throws WxErrorException { WxMpGuideImgMaterialInfoList guideImageMaterial = this.wxService.getGuideMaterialService().getGuideImageMaterial(0, 0, 20); assertThat(guideImageMaterial).isNotNull(); } @Test public void testDelGuideImageMaterial() throws WxErrorException { this.wxService.getGuideMaterialService().delGuideImageMaterial(0, "http://mmbiz.qpic.cn/mmbiz_png/63bwCoCgX0neicbffKiaL4vqXAUChYwE1VO0ZG5b6SW3Shv7kR1ia46b3gS8zf78piaR7vk7I6MRqbVzibJVJoNtkEg/0"); } @Test public void testSetGuideWordMaterial() throws WxErrorException { this.wxService.getGuideMaterialService().setGuideWordMaterial(0, "文字素材测试"); } @Test public void testGetGuideWordMaterial() throws WxErrorException { WxMpGuideWordMaterialInfoList guideWordMaterial = this.wxService.getGuideMaterialService().getGuideWordMaterial(0, 0, 20); assertThat(guideWordMaterial).isNotNull(); } @Test public void testDelGuideWordMaterial() throws WxErrorException { this.wxService.getGuideMaterialService().delGuideWordMaterial(0, "文字素材测试"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDraftServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDraftServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.draft.*; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /** * 草稿箱单元测试. * * @author dragon * created on 2021-10-22 */ @Guice(modules = ApiTestModule.class) public class WxMpDraftServiceImplTest { /** * 1.先上传一个永久图片素材:{@link me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImplTest#testUploadMaterial} * 2.后续图文需要设置一个永久素材id */ final String thumbMediaId = "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS"; /** * 新增草稿后返回的id,后续查询、修改、删除,获取等需要使用 */ final String mediaId = "-V3dxNv-eyJlImuJjWrmaZLwMkTKfDEhzq5NURU02H-k1qHMJ0lh9p0UU46w3rbd"; @Inject protected WxMpService wxService; @Test public void testAddDraft() throws WxErrorException { // {"mediaId":"zUUtT8ZYeXzZ4slFbtnAkh7Yd-f45DbFoF9ERzVC6s4","url":"http://mmbiz.qpic.cn/mmbiz_jpg/fLtyChQRfH84IyicNUbGt3l3IlHxJRibSFz7Tky0ibmzKykzVbo9tZGYhXQGJ2npFtDPbvPhKYxBz6JxkYIibTmUicQ/0?wx_fmt=jpeg"} this.wxService.getDraftService().addDraft("标题", "图文消息的具体内容", thumbMediaId); // 【响应数据】:{"media_id":"zUUtT8ZYeXzZ4slFbtnAks-nZeGiPQmwvhShTh72CqM","item":[]} } @Test public void testAddGuide_another() throws WxErrorException { List<WxMpDraftArticles> draftArticleList = new ArrayList<>(); WxMpDraftArticles draftArticle = WxMpDraftArticles.builder() .title("新建草稿-对象形式") .author("dragon") .digest("图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空") .content("图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS") .contentSourceUrl("https://github.com/Wechat-Group/WxJava") .thumbMediaId(thumbMediaId) // 显示封面、打开评论、所有人可评论 .showCoverPic(1).needOpenComment(1).onlyFansCanComment(0) .picCrop2351("0.1945_0_1_0.5236") .picCrop11("0.1945_0_1_0.5236") .build(); draftArticleList.add(draftArticle); WxMpAddDraft addDraft = WxMpAddDraft.builder().articles(draftArticleList).build(); String mediaId = this.wxService.getDraftService().addDraft(addDraft); // 【响应数据】:{"media_id":"zUUtT8ZYeXzZ4slFbtnAkpgGKyqnTsjtUvMdVBRWJVk","item":[]} assertThat(mediaId).isNotNull(); } @Test public void testGetDraft() throws WxErrorException { final WxMpDraftInfo draftInfo = this.wxService.getDraftService().getDraft(mediaId); assertThat(draftInfo).isNotNull(); // 【响应数据】:{"news_item":[{"title":"标题","author":"","digest":"图文消息的具体内容","content":"图文消息的具体内容","content_source_url":"","thumb_media_id":"zUUtT8ZYeXzZ4slFbtnAkh7Yd-f45DbFoF9ERzVC6s4","show_cover_pic":1,"url":"http:\/\/mp.weixin.qq.com\/s?__biz=Mzk0OTI5MzM1OQ==&mid=100000006&idx=1&sn=89903965ae5ebd6014903c7c5ca34daa&chksm=435bd946742c5050d18da32289904db5ede8bbd157d181438231a1762b85030419b3c0ed4c00#rd","thumb_url":"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/fLtyChQRfH84IyicNUbGt3l3IlHxJRibSFz7Tky0ibmzKykzVbo9tZGYhXQGJ2npFtDPbvPhKYxBz6JxkYIibTmUicQ\/0?wx_fmt=jpeg","need_open_comment":0,"only_fans_can_comment":0}],"create_time":1634886802,"update_time":1634886802} } @Test public void testUpdateDraft() throws WxErrorException { WxMpDraftArticles draftArticles = WxMpDraftArticles.builder() .title("新标题").content("新图文消息的具体内容").thumbMediaId(thumbMediaId) .picCrop2351("0.1945_0_1_0.5236") .picCrop11("0.1945_0_1_0.5236") .build(); WxMpUpdateDraft updateDraft = WxMpUpdateDraft.builder() .mediaId(mediaId) .index(0) .articles(draftArticles) .build(); Boolean updateDraftResult = this.wxService.getDraftService().updateDraft(updateDraft); // assertThat(updateDraftResult).isTrue(); assertThat(updateDraftResult).isTrue(); } @Test public void testDelDraft() throws WxErrorException { Boolean delDraftResult = this.wxService.getDraftService().delDraft(mediaId); // 【响应数据】:{"errcode":0,"errmsg":"ok"} assertThat(delDraftResult).isTrue(); } @Test public void testListDraft() throws WxErrorException { WxMpDraftList draftList = this.wxService.getDraftService().listDraft(0, 10); /* 【响应数据】:{"item":[{"media_id":"zUUtT8ZYeXzZ4slFbtnAks-nZeGiPQmwvhShTh72CqM", "content":{ "news_item": [ {"title":"标题","author":"","digest":"图文消息的具体内容","content":"图文消息的具体内容", "content_source_url":"","thumb_media_id":"zUUtT8ZYeXzZ4slFbtnAkh7Yd-f45DbFoF9ERzVC6s4", "show_cover_pic":1,"url":"http:\/\/mp.weixin.qq.com\/s?__biz=Mzk0OTI5MzM1?wx_fmt=jpeg", "need_open_comment":0,"only_fans_can_comment":0}], "create_time":1634886802,"update_time":1634886802},"update_time":1634886802} ] ,"total_count":1,"item_count":1} */ System.out.println(draftList); assertThat(draftList).isNotNull(); } @Test public void testCountDraft() throws WxErrorException { Long countDraft = this.wxService.getDraftService().countDraft(); // 【响应数据】:{"total_count":1} assertThat(countDraft).isNotNull(); } //-----以下是图片类型草稿测试 /** * 先上传一个永久图片素材:{@link me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImplTest#testUploadMaterial} * 这里的图片,使用的是 mm.jpeg */ @Test public void testAddDraftPic() throws WxErrorException { List<WxMpDraftArticles> draftArticleList = new ArrayList<>(); ArrayList<WxMpDraftImageInfo.ImageItem> imageItems = new ArrayList<>(); imageItems.add(new WxMpDraftImageInfo.ImageItem(thumbMediaId)); ArrayList<WxMpDraftCoverInfo.CropPercent> cropPercents = new ArrayList<>(); cropPercents.add(new WxMpDraftCoverInfo.CropPercent("1_1", "0.1", "0", "1", "0.9")); WxMpDraftArticles draftArticle = WxMpDraftArticles.builder() .articleType(WxConsts.ArticleType.NEWS_PIC) .title("新建图片草稿") .content("图片消息的具体内容") // 打开评论、所有人可评论 .needOpenComment(1).onlyFansCanComment(0) .imageInfo(WxMpDraftImageInfo.builder().imageList(imageItems).build()) .coverInfo(WxMpDraftCoverInfo.builder().cropPercentList(cropPercents).build()) .productInfo(WxMpDraftProductInfo.builder().footerProductInfo(new WxMpDraftProductInfo.FooterProductInfo("")).build()) .build(); draftArticleList.add(draftArticle); WxMpAddDraft addDraft = WxMpAddDraft.builder().articles(draftArticleList).build(); String mediaId = this.wxService.getDraftService().addDraft(addDraft); System.out.println(mediaId); assertThat(mediaId).isNotNull(); } @Test public void testGetDraftPic() throws WxErrorException { final WxMpDraftInfo draftInfo = this.wxService.getDraftService().getDraft(mediaId); assertThat(draftInfo).isNotNull(); System.out.println(draftInfo.toJson()); // 【响应数据】:{ // "news_item": [ // { // "article_type": "newspic", // "title": "新建图片草稿", // "content": "图片消息的具体内容", // "thumb_media_id": "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS", // "need_open_comment": 1, // "only_fans_can_comment": 0, // "url": "http://mp.weixin.qq.com/s?__biz=MzkyNTg4NDM1NA==&tempkey=MTMyM18rUktkOHFIQm5Kd3U5Rk1yS2NRYWtyZWUyNDNwS2MxZTZ3VXBKTkVScExpUFdGYzN2X0IzOEl1NGxEMGFpYld6NmdvbE9UUzlyYUdiVklvWTQ2YlRzSkkzQlpWMEZpcG9JRWp5LWZCVVNoWURodUlfWnE4VWZVQnlPd2VaUkg5SGREYUd3TW1wQkhlbTFuenBvRzFIbUxhMEJVbEo0Z3oyd2tnSGJBfn4%3D&chksm=423e8b9e75490288e8388c9ee91d6dad462bbce654742edd316622ab2b2fcfc593a4db58577b#rd", // "thumb_url": "http://mmbiz.qpic.cn/sz_mmbiz_jpg/s7FE7rYN42QgPuJeXX9MfNuJBiaoalrWv8fj4AEqnK0WBM3KzqS0DsqHIW4epA3cx1PGjpco87BTssgQibvSNBIQ/0?wx_fmt=jpeg", // "image_info": { // "image_list": [ // { // "image_media_id": "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS" // } // ] // } // } // ] // } } @Test public void testUpdateDraftPic() throws WxErrorException { ArrayList<WxMpDraftImageInfo.ImageItem> imageItems = new ArrayList<>(); imageItems.add(new WxMpDraftImageInfo.ImageItem(thumbMediaId)); ArrayList<WxMpDraftCoverInfo.CropPercent> cropPercents = new ArrayList<>(); cropPercents.add(new WxMpDraftCoverInfo.CropPercent("1_1", "0.3", "0", "1", "0.7")); WxMpDraftArticles draftArticle = WxMpDraftArticles.builder() .articleType(WxConsts.ArticleType.NEWS_PIC) .title("修改图片草稿") .content("修改后的图片消息的具体内容") // 打开评论、所有人可评论 .needOpenComment(1).onlyFansCanComment(0) .imageInfo(WxMpDraftImageInfo.builder().imageList(imageItems).build()) .coverInfo(WxMpDraftCoverInfo.builder().cropPercentList(cropPercents).build()) .productInfo(WxMpDraftProductInfo.builder().footerProductInfo(new WxMpDraftProductInfo.FooterProductInfo("")).build()) .build(); WxMpUpdateDraft updateDraft = WxMpUpdateDraft.builder() .mediaId(mediaId) .index(0) .articles(draftArticle) .build(); Boolean updateDraftResult = this.wxService.getDraftService().updateDraft(updateDraft); assertThat(updateDraftResult).isTrue(); } @Test public void testDelDraftPic() throws WxErrorException { Boolean delDraftResult = this.wxService.getDraftService().delDraft(mediaId); System.out.println(delDraftResult); // 【响应数据】:{"errcode":0,"errmsg":"ok"} assertThat(delDraftResult).isTrue(); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.api.test.TestConfigStorage; import me.chanjar.weixin.mp.api.test.TestConstants; import me.chanjar.weixin.mp.bean.WxMpMassNews; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; import me.chanjar.weixin.mp.bean.WxMpMassVideo; import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull; /** * 测试群发消息 * * @author chanjarster */ @Test @Guice(modules = ApiTestModule.class) public class WxMpMassMessageServiceImplTest { @Inject protected WxMpService wxService; @Test public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 TestConfigStorage configProvider = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(WxConsts.MassMsgType.TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService.getMassMessageService().massOpenIdsMessageSend(massMessage); assertNotNull(massResult); assertNotNull(massResult.getMsgId()); } @Test(dataProvider = "massMessages") public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException { // 发送群发消息 TestConfigStorage configProvider = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); massMessage.getToUsers().add(configProvider.getOpenid()); WxMpMassSendResult massResult = this.wxService.getMassMessageService().massOpenIdsMessageSend(massMessage); assertNotNull(massResult); assertNotNull(massResult.getMsgId()); } @Test public void testImagesMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 List<String> massMsg = new ArrayList<>(); for (int i = 0; i < 2; i++) { try (InputStream inputStream = ClassLoader .getSystemResourceAsStream(i + ".jpeg")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); massMsg.add(uploadMediaRes.getMediaId()); } catch (IOException e) { e.printStackTrace(); } } WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); massMessage.setMsgType(WxConsts.MassMsgType.IMAGE); massMessage.setMediaIds(new ArrayList<>(massMsg)); massMessage.setSendAll(true); WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage); assertNotNull(massResult); assertNotNull(massResult.getMsgId()); } @Test public void testTextMassGroupMessageSend() throws WxErrorException { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); massMessage.setMsgType(WxConsts.MassMsgType.TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); massMessage .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage); assertNotNull(massResult); assertNotNull(massResult.getMsgId()); } @Test(dataProvider = "massMessages") public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException { WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage); assertNotNull(massResult); assertNotNull(massResult.getMsgId()); } @DataProvider public Object[][] massMessages() throws WxErrorException, IOException { Object[][] messages = new Object[4][]; /* * 视频素材 */ try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.mp4")) { // 上传视频到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.VIDEO, TestConstants.FILE_MP4, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); // 把视频变成可被群发的媒体 WxMpMassVideo video = new WxMpMassVideo(); video.setTitle("测试标题"); video.setDescription("测试描述"); video.setMediaId(uploadMediaRes.getMediaId()); WxMpMassUploadResult uploadResult = this.wxService.getMassMessageService().massVideoUpload(video); assertNotNull(uploadResult); assertNotNull(uploadResult.getMediaId()); messages[0] = new Object[]{WxConsts.MassMsgType.MPVIDEO, uploadResult.getMediaId()}; } /* * 图片素材 */ try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.jpeg")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); messages[1] = new Object[]{WxConsts.MassMsgType.IMAGE, uploadMediaRes.getMediaId() }; } /* * 语音素材 */ try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.mp3")) { WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.VOICE, TestConstants.FILE_MP3, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); messages[2] = new Object[]{WxConsts.MassMsgType.VOICE, uploadMediaRes.getMediaId()}; } /* * 图文素材 */ try (InputStream inputStream = ClassLoader .getSystemResourceAsStream("mm.jpeg")) { // 上传照片到媒体库 WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() .mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream); assertNotNull(uploadMediaRes); assertNotNull(uploadMediaRes.getMediaId()); // 上传图文消息 WxMpMassNews news = new WxMpMassNews(); WxMpNewsArticle article1 = new WxMpNewsArticle(); article1.setTitle("标题1"); article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1"); article1.setThumbMediaId(uploadMediaRes.getMediaId()); news.addArticle(article1); WxMpNewsArticle article2 = new WxMpNewsArticle(); article2.setTitle("标题2"); article2.setContent("内容2内容2内容2内容2内容2内容2内容2内容2内2内容2内容2内容2内容2内容2内容2内容2内容2内容2"); article2.setThumbMediaId(uploadMediaRes.getMediaId()); article2.setShowCoverPic(true); article2.setAuthor("作者2"); article2.setContentSourceUrl("www.baidu.com"); article2.setDigest("摘要2"); news.addArticle(article2); WxMpMassUploadResult massUploadResult = this.wxService.getMassMessageService() .massNewsUpload(news); assertNotNull(massUploadResult); assertNotNull(uploadMediaRes.getMediaId()); messages[3] = new Object[]{WxConsts.MassMsgType.MPNEWS, massUploadResult.getMediaId()}; } return messages; } @Test public void testMassDelete() throws Exception { this.wxService.getMassMessageService().delete(1L, 2); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpQrcodeServiceImplTest.java
package me.chanjar.weixin.mp.api.impl; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.RandomStringUtils; import org.testng.*; import org.testng.annotations.*; import java.io.File; import java.io.IOException; /** * 测试用户相关的接口 * * @author chanjarster */ @Test(groups = "qrCodeAPI") @Guice(modules = ApiTestModule.class) public class WxMpQrcodeServiceImplTest { @Inject protected WxMpService wxService; @DataProvider public Object[][] sceneIds() { return new Object[][]{{-1}, {0}, {1}, {200000}}; } @DataProvider public Object[][] sceneStrs() { return new Object[][]{{null}, {""}, {"test"}, {RandomStringUtils.randomAlphanumeric(100)}}; } @Test(dataProvider = "sceneIds") public void testQrCodeCreateTmpTicket(int sceneId) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpireSeconds() != -1); System.out.println(ticket); } @Test(dataProvider = "sceneStrs") public void testQrCodeCreateTmpTicketWithSceneStr(String sceneStr) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(sceneStr, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpireSeconds() != -1); System.out.println(ticket); } @Test(dataProvider = "sceneIds") public void testQrCodeCreateLastTicket(int sceneId) throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(sceneId); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpireSeconds() == -1); System.out.println(ticket); } public void testQrCodePicture() throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1); File file = this.wxService.getQrcodeService().qrCodePicture(ticket); Assert.assertNotNull(file); System.out.println(file.getAbsolutePath()); try { FileUtils.copyFile(file,new File("d:\\t.jpg")); } catch (IOException e) { e.printStackTrace(); } } public void testQrCodePictureUrl() throws WxErrorException { WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1); String url = this.wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket()); Assert.assertNotNull(url); System.out.println(url); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/card/membercard/WxMpMemberCardUpdateResultTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/card/membercard/WxMpMemberCardUpdateResultTest.java
package me.chanjar.weixin.mp.bean.card.membercard; import org.testng.annotations.Test; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; /** * * @author YuJian * @version 2017/7/15 */ public class WxMpMemberCardUpdateResultTest { @Test public void testFromJson() throws Exception { String json = "{\n" + " \"errcode\": 0,\n" + " \"errmsg\": \"ok\",\n" + " \"result_bonus\": 100,\n" + " \"result_balance\": 200,\n" + " \"openid\": \"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA\"\n" + "}"; WxMpMemberCardUpdateResult result = WxMpMemberCardUpdateResult.fromJson(json); assertNotNull(result); assertTrue(result.getErrorCode().equalsIgnoreCase("0")); System.out.println(result); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/card/membercard/WxMpMemberCardUserInfoResultTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/card/membercard/WxMpMemberCardUserInfoResultTest.java
package me.chanjar.weixin.mp.bean.card.membercard; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; /** * * @author YuJian * @version 2017/7/15 */ public class WxMpMemberCardUserInfoResultTest { @Test public void testFromJson() throws Exception { String json = "{\n" + " \"errcode\": 0,\n" + " \"errmsg\": \"ok\",\n" + " \"openid\": \"obLatjjwDolFj******wNqRXw\",\n" + " \"nickname\": \"*******\",\n" + " \"membership_number\": \"658*****445\",\n" + " \"bonus\": 995,\n" + " \"sex\": \"MALE\",\n" + " \"user_info\": {\n" + " \"common_field_list\": [\n" + " {\n" + " \"name\": \"USER_FORM_INFO_FLAG_MOBILE\",\n" + " \"value\": \"15*****518\"\n" + " },\n" + " {\n" + " \"name\": \"USER_FORM_INFO_FLAG_NAME\",\n" + " \"value\": \"HK\"\n" + " },\n" + " {\n" + " \"name\": \"USER_FORM_INFO_FLAG_EDUCATION_BACKGROUND\",\n" + " \"value\": \"研究生\"\n" + " }\n" + " ],\n" + " \"custom_field_list\": [\n" + " {\n" + " \"name\": \"兴趣\",\n" + " \"value\": \"钢琴\",\n" + " \"value_list\": []\n" + " },\n" + " {\n" + " \"name\": \"喜好\",\n" + " \"value\": \"郭敬明\",\n" + " \"value_list\": []\n" + " },\n" + " {\n" + " \"name\": \"职业\",\n" + " \"value\": \"\",\n" + " \"value_list\": [\n" + " \"赛车手\",\n" + " \"旅行家\"\n" + " ]\n" + " }\n" + " ]\n" + " },\n" + " \"user_card_status\": \"NORMAL\",\n" + " \"has_active\": false\n" + "}"; WxMpMemberCardUserInfoResult userInfoResult = WxMpMemberCardUserInfoResult.fromJson(json); assertNotNull(userInfoResult); assertFalse(userInfoResult.getHasActive()); assertTrue(userInfoResult.getSex().equalsIgnoreCase("MALE")); assertNotNull(userInfoResult.getUserInfo()); assertNotNull(userInfoResult.getUserInfo().getCommonFieldList()); assertNotNull(userInfoResult.getUserInfo().getCustomFieldList()); assertTrue(userInfoResult.getUserInfo().getCommonFieldList().length == 3); assertTrue(userInfoResult.getUserInfo().getCustomFieldList()[2].getValueList()[0].equalsIgnoreCase("赛车手")); System.out.println(userInfoResult); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpCurrentAutoReplyInfoTest.java
package me.chanjar.weixin.mp.bean.result; import org.testng.annotations.*; import static org.testng.Assert.*; /** * <pre> * Created by Binary Wang on 2017-7-8. * @author <a href="https://github.com/binarywang">Binary Wang</a> * </pre> */ public class WxMpCurrentAutoReplyInfoTest { @Test public void testFromJson() throws Exception { String json = "{ \n" + " \"is_add_friend_reply_open\": 1, \n" + " \"is_autoreply_open\": 1, \n" + " \"add_friend_autoreply_info\": { \n" + " \"type\": \"text\", \n" + " \"content\": \"Thanks for your attention!\"\n" + " }, \n" + " \"message_default_autoreply_info\": { \n" + " \"type\": \"text\", \n" + " \"content\": \"Hello, this is autoreply!\"\n" + " }, \n" + " \"keyword_autoreply_info\": { \n" + " \"list\": [ \n" + " { \n" + " \"rule_name\": \"autoreply-news\", \n" + " \"create_time\": 1423028166, \n" + " \"reply_mode\": \"reply_all\", \n" + " \"keyword_list_info\": [ \n" + " { \n" + " \"type\": \"text\", \n" + " \"match_mode\": \"contain\", \n" + " \"content\": \"news测试\"//此处content即为关键词内容\n" + " }\n" + " ], \n" + " \"reply_list_info\": [ \n" + " { \n" + " \"type\": \"news\", \n" + " \"news_info\": { \n" + " \"list\": [ \n" + " { \n" + " \"title\": \"it's news\", \n" + " \"author\": \"jim\", \n" + " \"digest\": \"it's digest\", \n" + " \"show_cover\": 1, \"cover_url\": \"http://mmbiz.qpic.cn/mmbiz/GE7et87vE9vicuCibqXsX9GPPLuEtBfXfKbE8sWdt2DDcL0dMfQWJWTVn1N8DxI0gcRmrtqBOuwQH\n" + " euPKmFLK0ZQ/0\", \n" + " \"content_url\": \"http://mp.weixin.qq.com/s?__biz=MjM5ODUwNTM3Ng==&mid=203929886&idx=1&sn=628f964cf0c6d84c026881b6959aea8b#rd\", \n" + " \"source_url\": \"http://www.url.com\"\n" + " }\n" + " ]\n" + " }\n" + " }, \n" + " { \n" + " \"type\": \"news\",\n" + " \"content\":\"KQb_w_Tiz-nSdVLoTV35Psmty8hGBulGhEdbb9SKs-o\", \n" + " \"news_info\": { \n" + " \"list\": [ \n" + " { \n" + " \"title\": \"MULTI_NEWS\", \n" + " \"author\": \"JIMZHENG\", \n" + " \"digest\": \"text\", \n" + " \"show_cover\": 0, \n" + " \"cover_url\": \"http://mmbiz.qpic.cn/mmbiz/GE7et87vE9vicuCibqXsX9GPPLuEtBfXfK0HKuBIa1A1cypS0uY1wickv70iaY1gf3I1DTszuJoS3lAVLv\n" + "hTcm9sDA/0\", \n" + " \"content_url\": \"http://mp.weixin.qq.com/s?__biz=MjM5ODUwNTM3Ng==&mid=204013432&idx=1&sn=80ce6d9abcb832237bf86c87e50fda15#rd\", \n" + " \"source_url\": \"\"\n" + " },\n" + " { \n" + " \"title\": \"MULTI_NEWS4\", \n" + " \"author\": \"JIMZHENG\", \n" + " \"digest\": \"MULTI_NEWSMULTI_NEWSMULTI_NEWSMULTI_NEWSMULTI_NEWSMULT\", \n" + " \"show_cover\": 1, \n" + "\"cover_url\": \"http://mmbiz.qpic.cn/mmbiz/GE7et87vE9vicuCibqXsX9GPPLuEtBfXfKbE8sWdt2DDcL0dMfQWJWTVn1N8DxI0gcRmrtqBOuwQ\n" + "HeuPKmFLK0ZQ/0\", \n" + " \"content_url\": \"http://mp.weixin.qq.com/s?__biz=MjM5ODUwNTM3Ng==&mid=204013432&idx=5&sn=b4ef73a915e7c2265e437096582774af#rd\", \n" + " \"source_url\": \"\"\n" + " }\n" + " ]\n" + " }\n" + " }\n" + " ]\n" + " }, \n" + " { \n" + " \"rule_name\": \"autoreply-voice\", \n" + " \"create_time\": 1423027971, \n" + " \"reply_mode\": \"random_one\", \n" + " \"keyword_list_info\": [ \n" + " { \n" + " \"type\": \"text\", \n" + " \"match_mode\": \"contain\", \n" + " \"content\": \"voice测试\"\n" + " }\n" + " ], \n" + " \"reply_list_info\": [ \n" + " { \n" + " \"type\": \"voice\", \n" + " \"content\": \"NESsxgHEvAcg3egJTtYj4uG1PTL6iPhratdWKDLAXYErhN6oEEfMdVyblWtBY5vp\"\n" + " }\n" + " ]\n" + " }, \n" + " { \n" + " \"rule_name\": \"autoreply-text\", \n" + " \"create_time\": 1423027926, \n" + " \"reply_mode\": \"random_one\", \n" + " \"keyword_list_info\": [ \n" + " { \n" + " \"type\": \"text\", \n" + " \"match_mode\": \"contain\", \n" + " \"content\": \"text测试\"\n" + " }\n" + " ], \n" + " \"reply_list_info\": [ \n" + " { \n" + " \"type\": \"text\", \n" + " \"content\": \"hello!text!\"\n" + " }\n" + " ]\n" + " }, \n" + " { \n" + " \"rule_name\": \"autoreply-video\", \n" + " \"create_time\": 1423027801, \n" + " \"reply_mode\": \"random_one\", \n" + " \"keyword_list_info\": [ \n" + " { \n" + " \"type\": \"text\", \n" + " \"match_mode\": \"equal\", \n" + " \"content\": \"video测试\"\n" + " }\n" + " ], \n" + " \"reply_list_info\": [ \n" + " { \n" + " \"type\": \"video\", \n" + "\"content\": \"http://61.182.133.153/vweixinp.tc.qq.com/1007_114bcede9a2244eeb5ab7f76d951df5f.f10.mp4?vkey=7183E5C952B16C3AB1991BA8138673DE1037CB82A29801A504B64A77F691BF9DF7AD054A9B7FE683&sha=0&save=1\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + "}"; WxMpCurrentAutoReplyInfo autoReplyInfo = WxMpCurrentAutoReplyInfo.fromJson(json); assertNotNull(autoReplyInfo); assertTrue(autoReplyInfo.getIsAddFriendReplyOpen()); assertTrue(autoReplyInfo.getIsAutoReplyOpen()); assertNotNull(autoReplyInfo.getAddFriendAutoReplyInfo()); assertNotNull(autoReplyInfo.getMessageDefaultAutoReplyInfo()); assertTrue(autoReplyInfo.getKeywordAutoReplyInfo().getList().size() > 0); System.out.println(autoReplyInfo); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpAdLeadResultTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/result/WxMpAdLeadResultTest.java
package me.chanjar.weixin.mp.bean.result; import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult; import org.testng.annotations.Test; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; /** * @author <a href="https://github.com/007gzs">007</a> */ public class WxMpAdLeadResultTest { @Test public void testFromJson() throws Exception { String json = "{\n" + "\t\"data\": {\n" + "\t\t\"page_info\": {\n" + "\t\t\t\"total_number\": 39,\n" + "\t\t\t\"page\": 1,\n" + "\t\t\t\"page_size\": 100,\n" + "\t\t\t\"total_page\": 1\n" + "\t\t},\n" + "\t\t\"list\": [{\n" + "\t\t\t\"click_id\": \"<click_id1>\",\n" + "\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" + "\t\t\t\"campaign_id\": 1800000001,\n" + "\t\t\t\"leads_info\": [{\n" + "\t\t\t\t\"value\": \"13800138000\",\n" + "\t\t\t\t\"key\": \"电话号码\"\n" + "\t\t\t}, {\n" + "\t\t\t\t\"value\": \"2019-03-14 00:54:34\",\n" + "\t\t\t\t\"key\": \"提交时间\"\n" + "\t\t\t}, {\n" + "\t\t\t\t\"value\": \"123\",\n" + "\t\t\t\t\"key\": \"自定义问题\"\n" + "\t\t\t}],\n" + "\t\t\t\"agency_name\": \"\",\n" + "\t\t\t\"agency_id\": \"\",\n" + "\t\t\t\"campaign_name\": \"<campaign_name>\",\n" + "\t\t\t\"adgroup_id\": 1800000002\n" + "\t\t}, {\n" + "\t\t\t\"click_id\": \"<click_id2>\",\n" + "\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" + "\t\t\t\"campaign_id\": 1800000001,\n" + "\t\t\t\"leads_info\": [{\n" + "\t\t\t\t\"value\": \"13800138001\",\n" + "\t\t\t\t\"key\": \"电话号码\"\n" + "\t\t\t}, {\n" + "\t\t\t\t\"value\": \"2019-03-14 02:10:39\",\n" + "\t\t\t\t\"key\": \"提交时间\"\n" + "\t\t\t}, {\n" + "\t\t\t\t\"value\": \"321\",\n" + "\t\t\t\t\"key\": \"自定义问题\"\n" + "\t\t\t}],\n" + "\t\t\t\"agency_name\": \"\",\n" + "\t\t\t\"agency_id\": \"\",\n" + "\t\t\t\"campaign_name\": \"<campaign_name>\",\n" + "\t\t\t\"adgroup_id\": 1800000002\n" + "\t\t}]\n" + "\t},\n" + "\t\"errcode\": 0,\n" + "\t\"errmsg\": \"\"\n" + "}"; WxMpAdLeadResult adLeadResult = WxMpAdLeadResult.fromJson(json); assertNotNull(adLeadResult); assertNotNull(adLeadResult.getPageInfo()); assertNotNull(adLeadResult.getAdLeads()); assertTrue(adLeadResult.getAdLeads().size() > 0); System.out.println(adLeadResult); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/subscribe/WxMpSubscribeMessageTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/subscribe/WxMpSubscribeMessageTest.java
package me.chanjar.weixin.mp.bean.subscribe; import org.testng.annotations.*; import java.io.Serializable; import java.util.Arrays; import static org.testng.AssertJUnit.*; /** * @author Mklaus * created on 2018-01-22 下午1:41 */ public class WxMpSubscribeMessageTest { @Test public void testToJson() { String actual = "{" + "\"touser\":\"OPENID\"," + "\"template_id\":\"TEMPLATE_ID\"," + "\"url\":\"URL\"," + "\"miniprogram\":{" + "\"appid\":\"xiaochengxuappid12345\"," + "\"pagepath\":\"index?foo=bar\"" + "}," + "\"scene\":\"SCENE\"," + "\"title\":\"TITLE\"," + "\"data\":{" + "\"content\":{" + "\"value\":\"VALUE\"," + "\"color\":\"COLOR\"" + "}" + "}" + "}"; WxMpSubscribeMessage message = WxMpSubscribeMessage.builder() .toUser("OPENID") .templateId("TEMPLATE_ID") .url("URL") .miniProgram(new WxMpSubscribeMessage.MiniProgram("xiaochengxuappid12345", "index?foo=bar",false)) .scene("SCENE") .title("TITLE") .contentValue("VALUE") .contentColor("COLOR") .build(); assertEquals(message.toJson(), actual); } @Test void testWxMpSubscribeMessageIsSerializable() { assertTrue(Arrays.stream(WxMpSubscribeMessage.class.getInterfaces()).anyMatch(anInterface -> anInterface.isInstance(Serializable.class))); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false
binarywang/WxJava
https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/kefu/WxMpKefuMessageTest.java
package me.chanjar.weixin.mp.bean.kefu; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; import org.testng.Assert; import org.testng.annotations.Test; @Test public class WxMpKefuMessageTest { public void testTextReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.TEXT); reply.setContent("sfsfdsdf"); Assert .assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testTextBuild() { WxMpKefuMessage reply = WxMpKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); Assert .assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testImageReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.IMAGE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testImageBuild() { WxMpKefuMessage reply = WxMpKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.VOICE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceBuild() { WxMpKefuMessage reply = WxMpKefuMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVideoReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.VIDEO); reply.setMediaId("MEDIA_ID"); reply.setThumbMediaId("MEDIA_ID"); reply.setTitle("TITLE"); reply.setDescription("DESCRIPTION"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testVideoBuild() { WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID") .thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testMusicReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.MUSIC); reply.setThumbMediaId("MEDIA_ID"); reply.setDescription("DESCRIPTION"); reply.setTitle("TITLE"); reply.setMusicUrl("MUSIC_URL"); reply.setHqMusicUrl("HQ_MUSIC_URL"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } public void testMusicBuild() { WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() .toUser("OPENID") .title("TITLE") .thumbMediaId("MEDIA_ID") .description("DESCRIPTION") .musicUrl("MUSIC_URL") .hqMusicUrl("HQ_MUSIC_URL") .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); } public void testNewsReply() { WxMpKefuMessage reply = new WxMpKefuMessage(); reply.setToUser("OPENID"); reply.setMsgType(WxConsts.KefuMsgType.NEWS); WxArticle article1 = new WxArticle(); article1.setUrl("URL"); article1.setPicUrl("PIC_URL"); article1.setDescription("Is Really A Happy Day"); article1.setTitle("Happy Day"); reply.getArticles().add(article1); WxArticle article2 = new WxArticle(); article2.setUrl("URL"); article2.setPicUrl("PIC_URL"); article2.setDescription("Is Really A Happy Day"); article2.setTitle("Happy Day"); reply.getArticles().add(article2); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); } public void testNewsBuild() { WxArticle article1 = new WxArticle(); article1.setUrl("URL"); article1.setPicUrl("PIC_URL"); article1.setDescription("Is Really A Happy Day"); article1.setTitle("Happy Day"); WxArticle article2 = new WxArticle(); article2.setUrl("URL"); article2.setPicUrl("PIC_URL"); article2.setDescription("Is Really A Happy Day"); article2.setTitle("Happy Day"); WxMpKefuMessage reply = WxMpKefuMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); } public void testMiniProgramPageBuild() { WxMpKefuMessage reply = WxMpKefuMessage.MINIPROGRAMPAGE() .toUser("OPENID") .title("title") .appId("appid") .pagePath("pagepath") .thumbMediaId("thumb_media_id") .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"miniprogrampage\",\"miniprogrampage\":{\"title\":\"title\",\"appid\":\"appid\",\"pagepath\":\"pagepath\",\"thumb_media_id\":\"thumb_media_id\"}}"); } public void testMsgMenuBuild() { WxMpKefuMessage reply = WxMpKefuMessage.MSGMENU() .toUser("OPENID") .addMenus(new WxMpKefuMessage.MsgMenu("101", "msgmenu1"), new WxMpKefuMessage.MsgMenu("102", "msgmenu2")) .headContent("head_content") .tailContent("tail_content") .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"msgmenu\",\"msgmenu\":{\"head_content\":\"head_content\",\"list\":[{\"id\":\"101\",\"content\":\"msgmenu1\"},{\"id\":\"102\",\"content\":\"msgmenu2\"}],\"tail_content\":\"tail_content\"}}"); } public void testMpNewsArticleBuilder() { WxMpKefuMessage reply = WxMpKefuMessage.MPNEWSARTICLE() .toUser("OPENID") .articleId("ARTICLE_ID") .build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"mpnewsarticle\",\"mpnewsarticle\":{\"article_id\":\"ARTICLE_ID\"}}"); } }
java
Apache-2.0
84b5c4d2d0774f800237634e5d0336f53c004fe3
2026-01-04T14:46:39.499027Z
false