1
0
mirror of synced 2025-12-23 18:48:00 +08:00

🎨 修复家校沟通部分接口问题

This commit is contained in:
0katekate0
2022-07-21 15:29:01 +08:00
committed by GitHub
parent bac18534dc
commit 8f301500ef
7 changed files with 425 additions and 15 deletions

View File

@@ -3,12 +3,17 @@ package me.chanjar.weixin.cp.api;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.constant.WxCpConsts;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
import org.eclipse.jetty.util.ajax.JSON;
import org.testng.annotations.Test;
import java.io.InputStream;
@@ -16,6 +21,7 @@ import java.io.InputStream;
/**
* 企业微信自建应用接口测试类.
* https://developer.work.weixin.qq.com/document/path/90269
* https://developer.work.weixin.qq.com/document/path/90240#%E5%AE%A1%E6%89%B9%E7%8A%B6%E6%80%81%E9%80%9A%E7%9F%A5%E4%BA%8B%E4%BB%B6
*
* @author <a href="https://gitee.com/Wang_Wong/">Wang_Wong</a>
* @date 2022-04-06
@@ -37,6 +43,148 @@ public class WxCpOaAgentTest {
cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config);
/**
* 测试 审批状态通知事件
*/
String testXml2 = "<xml>\n" +
" <ToUserName><![CDATA[wwddddccc7775555aaa]]></ToUserName>\n" +
" <FromUserName><![CDATA[sys]]></FromUserName>\n" +
" <CreateTime>1527838022</CreateTime>\n" +
" <MsgType><![CDATA[event]]></MsgType>\n" +
" <Event><![CDATA[open_approval_change]]></Event>\n" +
" <AgentID>1</AgentID>\n" +
" <ApprovalInfo>\n" +
" <ThirdNo><![CDATA[201806010001]]></ThirdNo>\n" +
" <OpenSpName><![CDATA[付款]]></OpenSpName>\n" +
" <OpenTemplateId><![CDATA[1234567890]]></OpenTemplateId>\n" +
" <OpenSpStatus>1</OpenSpStatus>\n" +
" <ApplyTime>1527837645</ApplyTime>\n" +
" <ApplyUserName><![CDATA[xiaoming]]></ApplyUserName>\n" +
" <ApplyUserId><![CDATA[1]]></ApplyUserId>\n" +
" <ApplyUserParty><![CDATA[产品部]]></ApplyUserParty>\n" +
" <ApplyUserImage><![CDATA[http://www.qq.com/xxx.png]]></ApplyUserImage>\n" +
" <ApprovalNodes>\n" +
" <ApprovalNode>\n" +
" <NodeStatus>1</NodeStatus>\n" +
" <NodeAttr>1</NodeAttr>\n" +
" <NodeType>1</NodeType>\n" +
" <Items>\n" +
" <Item>\n" +
" <ItemName><![CDATA[xiaohong]]></ItemName>\n" +
" <ItemUserId><![CDATA[2]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" <ItemStatus>1</ItemStatus>\n" +
" <ItemSpeech><![CDATA[]]></ItemSpeech>\n" +
" <ItemOpTime>0</ItemOpTime>\n" +
" </Item>\n" +
" </Items>\n" +
" </ApprovalNode>\n" +
" </ApprovalNodes>\n" +
" <NotifyNodes>\n" +
" <NotifyNode>\n" +
" <ItemName><![CDATA[xiaogang]]></ItemName>\n" +
" <ItemUserId><![CDATA[3]]></ItemUserId>\n" +
" <ItemImage><![CDATA[http://www.qq.com/xxx.png]]></ItemImage>\n" +
" </NotifyNode>\n" +
" </NotifyNodes>\n" +
" <approverstep>0</approverstep>\n" +
" </ApprovalInfo>\n" +
"</xml>\n";
final WxCpXmlMessage mess2 = XStreamTransformer.fromXml(WxCpXmlMessage.class, testXml2);
mess2.setAllFieldsMap(XmlUtils.xml2Map(testXml2));
log.info("xmlJson: {}", JSON.toString(mess2));
/**
* 测试 弹出微信相册发图器的事件推送
*
* https://developer.work.weixin.qq.com/document/path/90240
*/
String testXml = "<xml>\n" +
"\t<ToUserName><![CDATA[toUser]]></ToUserName>\n" +
"\t<FromUserName><![CDATA[FromUser]]></FromUserName>\n" +
"\t<CreateTime>1408090816</CreateTime>\n" +
"\t<MsgType><![CDATA[event]]></MsgType>\n" +
"\t<Event><![CDATA[pic_weixin]]></Event>\n" +
"\t<EventKey><![CDATA[6]]></EventKey>\n" +
"\t<SendPicsInfo><Count>1</Count>\n" +
"\t<PicList><item><PicMd5Sum><![CDATA[5a75aaca956d97be686719218f275c6b]]></PicMd5Sum>\n" +
"\t</item>\n" +
"\t</PicList>\n" +
"\t</SendPicsInfo>\n" +
"\t<AgentID>1</AgentID>\n" +
"</xml>\n";
final WxCpXmlMessage mess = XStreamTransformer.fromXml(WxCpXmlMessage.class, testXml);
mess.setAllFieldsMap(XmlUtils.xml2Map(testXml));
log.info("xmlJson: {}", JSON.toString(mess));
/**
* 审批流程引擎
* 自建应用审批状态变化通知回调
*
* https://developer.work.weixin.qq.com/document/path/90269
*/
String approvalInfoXml = "<xml>\n" +
" <ToUserName>wwd08c8e7c775abaaa</ToUserName> \n" +
" <FromUserName>sys</FromUserName> \n" +
" <CreateTime>1527838022</CreateTime> \n" +
" <MsgType>event</MsgType> \n" +
" <Event>open_approval_change</Event>\n" +
" <AgentID>1</AgentID>\n" +
" <ApprovalInfo> \n" +
" <ThirdNo>thirdNoxxx</ThirdNo> \n" +
" <OpenSpName>付款</OpenSpName> \n" +
" <OpenTemplateId>1234567111</OpenTemplateId> \n" +
" <OpenSpStatus>1</OpenSpStatus> \n" +
" <ApplyTime>1527837645</ApplyTime> \n" +
" <ApplyUserName>jackiejjwu</ApplyUserName> \n" +
" <ApplyUserId>WuJunJie</ApplyUserId> \n" +
" <ApplyUserParty>产品部</ApplyUserParty> \n" +
" <ApplyUserImage>http://www.qq.com/xxx.png</ApplyUserImage> \n" +
" <ApprovalNodes> \n" +
" <ApprovalNode> \n" +
" <NodeStatus>1</NodeStatus> \n" +
" <NodeAttr>1</NodeAttr> \n" +
" <NodeType>1</NodeType> \n" +
" <Items> \n" +
" <Item> \n" +
" <ItemName>chauvetxiao</ItemName> \n" +
" <ItemUserid>XiaoWen</ItemUserid> \n" +
" <ItemParty>产品部</ItemParty> \n" +
" <ItemImage>http://www.qq.com/xxx.png</ItemImage> \n" +
" <ItemStatus>1</ItemStatus> \n" +
" <ItemSpeech></ItemSpeech> \n" +
" <ItemOpTime>0</ItemOpTime> \n" +
" </Item> \n" +
" </Items> \n" +
" </ApprovalNode> \n" +
" </ApprovalNodes> \n" +
" <NotifyNodes> \n" +
" <NotifyNode> \n" +
" <ItemName>jinhuiguo</ItemName> \n" +
" <ItemUserid>GuoJinHui</ItemUserid> \n" +
" <ItemParty>行政部</ItemParty> \n" +
" <ItemImage>http://www.qq.com/xxx.png</ItemImage> \n" +
" </NotifyNode> \n" +
" </NotifyNodes> \n" +
" <ApproverStep>0</ApproverStep> \n" +
" </ApprovalInfo> \n" +
"</xml>\n";
final WxCpXmlMessage msg = XStreamTransformer.fromXml(WxCpXmlMessage.class, approvalInfoXml);
msg.setAllFieldsMap(XmlUtils.xml2Map(approvalInfoXml));
log.info("xmlJson: {}", JSON.toString(msg));
/**
* 增加
* 自建应用审批状态变化通知回调类型
*/
String openApprovalChange = WxCpConsts.EventType.OPEN_APPROVAL_CHANGE;
/**
* Test
*/

View File

@@ -9,11 +9,16 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
import me.chanjar.weixin.cp.bean.article.NewArticle;
import me.chanjar.weixin.cp.bean.school.user.WxCpAllowScope;
import me.chanjar.weixin.cp.bean.school.user.WxCpListParentResult;
import me.chanjar.weixin.cp.bean.school.user.WxCpUserListResult;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,20 +57,36 @@ public class WxCpSchoolContactMessageTest {
cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config);
// 获取可使用的家长范围 返回的数据
WxCpAllowScope allowScope = cpService.getSchoolUserService().getAllowScope(1000002);
WxCpUserListResult userList = cpService.getSchoolUserService().getUserList(1, 1);
// 测试发送给家长 [学校通知]
WxCpListParentResult userListParent = cpService.getSchoolUserService().getUserListParent(1);
List<WxCpListParentResult.Parent> collect = userListParent.getParents()
.stream()
.filter(parent -> parent.getMobile().equals("13079226621"))
.collect(Collectors.toList());
String[] parentsId = {"ab0b1691d0204d4900f6b7a7e5a6aa8f", collect.get(0).getParentUserId()};
WxCpSchoolContactMessageSendResult sendResult = this.cpService.getMessageService().sendSchoolContactMessage(
WxCpSchoolContactMessage.builder()
.recvScope(0)
.msgType(WxConsts.SchoolContactMsgType.TEXT)
.toParentUserId(new String[]{"parent_userid1", "parent_userid2"})
.toStudentUserId(new String[]{"student_userid1", "student_userid2"})
.toParty(new String[]{"partyid1", "partyid2"})
.msgType(WxConsts.SchoolContactMsgType.NEWS)
.toParentUserId(parentsId)
// .toStudentUserId(new String[]{"student_userid1", "student_userid2"})
// .toParty(new String[]{"partyid1", "partyid2"})
.toAll(false)
.agentId(1)
.content("你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。")
.enableIdTrans(false)
.enableDuplicateCheck(false)
.duplicateCheckInterval(1800)
.agentId(cpService.getWxCpConfigStorage().getAgentId())
.articles(Lists.newArrayList(NewArticle.builder()
.title("这是接口测试标题")
.description("今年中秋节公司有豪礼相送哦")
.url("https://www.baidu.com/")
.picUrl("http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png")
.build()))
.build()
);