use of me.chanjar.weixin.common.error.WxError in project project by Ahaochan.
the class BlacklistTest method getOpenIdsByBlacklist.
/**
* 获取公众号的黑名单列表, 每次最多 10000 个 openId
* @see <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1471422259_pJMWA">黑名单管理 获取公众号的黑名单列表</a>
*/
@Test
void getOpenIdsByBlacklist() {
String nextOpenId = null;
do {
try {
WxMpUserBlacklistGetResult result = blackListService.getBlacklist(nextOpenId);
System.out.println("总拉黑用户数量:" + result.getTotal());
System.out.println("本次拉取用户数量:" + result.getCount());
System.out.println("本次拉取的用户openId:" + result.getOpenidList());
System.out.println("-------------------------------------------------------");
if (Objects.equals(nextOpenId, result.getNextOpenid())) {
break;
}
nextOpenId = result.getNextOpenid();
} catch (WxErrorException e) {
WxError error = e.getError();
switch(error.getErrorCode()) {
case -1:
Assertions.fail(WxMpErrorMsgEnum.CODE_1.getMsg());
break;
case 40003:
Assertions.fail(WxMpErrorMsgEnum.CODE_40003.getMsg());
break;
case 49003:
Assertions.fail("传入的openid不属于此AppID");
break;
}
e.printStackTrace();
}
} while (StringUtils.isNotBlank(nextOpenId));
}
use of me.chanjar.weixin.common.error.WxError in project project by Ahaochan.
the class UserTagTest method createTag.
/**
* 创建用户标签, 一个公众号, 最多可以创建 100 个标签
* @param tagName 标签名
* @see <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837">用户标签管理 标签管理 创建标签</a>
*/
@ParameterizedTest
@ValueSource(strings = { "测试标签" })
void createTag(String tagName) {
try {
WxUserTag tag = tagService.tagCreate(tagName);
System.out.println("------------------------------------------------------");
System.out.println("标签Id:" + tag.getId());
System.out.println("标签名称:" + tag.getName());
} catch (WxErrorException e) {
WxError error = e.getError();
switch(error.getErrorCode()) {
case -1:
Assertions.fail(WxMpErrorMsgEnum.CODE_1.getMsg());
break;
case 45157:
Assertions.fail("标签名非法,请注意不能和其他标签重名");
break;
case 45158:
Assertions.fail("标签名长度超过30个字节");
break;
case 45056:
Assertions.fail("创建的标签数过多,请注意不能超过100个");
break;
}
e.printStackTrace();
}
}
use of me.chanjar.weixin.common.error.WxError in project project by Ahaochan.
the class UserTest method selectOpenIdListByTagId.
/**
* 获取标签下的粉丝 openId
* @param tagId 标签Id
* @see <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837">用户标签管理 标签管理 获取标签下粉丝列表</a>
*/
@ParameterizedTest
@ValueSource(longs = { 0, 1, 2, 101 })
void selectOpenIdListByTagId(Long tagId) {
String nextOpenId = null;
do {
try {
WxTagListUser userList = tagService.tagListUser(tagId, nextOpenId);
System.out.println("本次拉取该标签的粉丝数量:" + userList.getCount());
WxTagListUser.WxTagListUserData data = userList.getData();
if (data != null) {
System.out.println("本次拉取该标签的用户openId:" + data.getOpenidList());
}
System.out.println("-------------------------------------------------------");
nextOpenId = userList.getNextOpenid();
} catch (WxErrorException e) {
WxError error = e.getError();
switch(error.getErrorCode()) {
case -1:
Assertions.fail(WxMpErrorMsgEnum.CODE_1.getMsg());
break;
case 40003:
Assertions.fail(WxMpErrorMsgEnum.CODE_40003.getMsg());
break;
case 45159:
Assertions.fail("非法的tag_id");
break;
}
e.printStackTrace();
}
} while (StringUtils.isNotBlank(nextOpenId));
}
use of me.chanjar.weixin.common.error.WxError in project starshop by beautautumn.
the class WxSessionCheckingClientAdapter method code2session.
@Override
public void code2session(String code, WxAuthInfo wxAuthInfo) throws WxLoginErrorException {
final WxMaService wxService = WxConfiguration.getMaService();
try {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
wxAuthInfo.setOpenid(session.getOpenid());
wxAuthInfo.setSessionKey(session.getSessionKey());
} catch (WxErrorException e) {
WxError wxError = e.getError();
throw new WxLoginErrorException(wxError.getErrorCode(), wxError.getErrorMsg());
}
}
use of me.chanjar.weixin.common.error.WxError in project chao-cloud by chaojunzi.
the class WxAppUserInfoServiceImpl method getUserInfo.
@Override
public WxMaUserInfo getUserInfo(String encryptedData, String iv, String code) {
try {
// 获取session_key
log.info("[encryptedData={}]", encryptedData);
log.info("[iv={}]", iv);
WxMaJscode2SessionResult sessionInfo = wxMaUserService.getSessionInfo(code);
log.info("[sessionInfo={}]", sessionInfo);
// 获取用户信息
return wxMaUserService.getUserInfo(sessionInfo.getSessionKey(), getEncryptedData(encryptedData), iv);
} catch (WxErrorException e) {
WxError error = e.getError();
throw new BusinessException(error.getErrorMsg());
}
}
Aggregations