Skip to content

Commit 5e09c3e

Browse files
authored
🎨 #3808 【小程序】修复用工关系接口地址以及请求实体类字段错误的问题
1 parent a23429c commit 5e09c3e

File tree

6 files changed

+145
-31
lines changed

6 files changed

+145
-31
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ WxMaApiResponse execute(
625625
/**
626626
* 获取用工关系服务对象。
627627
* <br>
628-
* 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
628+
* 服务端api文档:https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/
629+
* 整体流程文档: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
629630
*
630631
* @return 用工关系服务对象WxMaEmployeeRelationService
631632
*/

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaEmployeeRelationServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1717
* created on 2025-12-19
18+
* update on 2026-01-22 15:06:33
1819
*/
1920
@RequiredArgsConstructor
2021
public class WxMaEmployeeRelationServiceImpl implements WxMaEmployeeRelationService {

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/employee/WxMaSendEmployeeMsgRequest.java

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
/**
1313
* 小程序推送用工消息请求实体
1414
* <p>
15-
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
15+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
1616
* </p>
1717
*
1818
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1919
* created on 2025-12-19
20+
* update on 2026-01-22 15:13:28
2021
*/
2122
@Data
2223
@Builder(builderMethodName = "newBuilder")
@@ -27,33 +28,74 @@ public class WxMaSendEmployeeMsgRequest implements Serializable {
2728

2829
/**
2930
* <pre>
30-
* 字段名:用户openid
31+
* 字段名:模板id
3132
* 是否必填:是
32-
* 描述:需要接收消息的用户openid
33+
* 描述:需要在微信后台申请用工关系权限,通过后创建的模板审核通过后可以复制模板ID
3334
* </pre>
3435
*/
35-
@SerializedName("openid")
36-
private String openid;
36+
@SerializedName("template_id")
37+
private String templateId;
3738

3839
/**
3940
* <pre>
40-
* 字段名:企业id
41+
* 字段名:页面
4142
* 是否必填:是
42-
* 描述:企业id,小程序管理员在微信开放平台配置
43+
* 描述:用工消息通知跳转的page小程序链接(注意 小程序页面链接要是申请模板的小程序)
4344
* </pre>
4445
*/
45-
@SerializedName("corp_id")
46-
private String corpId;
46+
@SerializedName("page")
47+
private String page;
48+
49+
/**
50+
* <pre>
51+
* 字段名:被推送用户的openId
52+
* 是否必填:是
53+
* 描述:被推送用户的openId
54+
* </pre>
55+
*/
56+
@SerializedName("touser")
57+
private String touser;
4758

4859
/**
4960
* <pre>
5061
* 字段名:消息内容
5162
* 是否必填:是
52-
* 描述:推送的消息内容,文本格式,最长不超过200个字符
63+
* 描述:需要根据小程序后台审核通过的模板id的字段类型序列化json传递
64+
*
65+
* </pre>
66+
*
67+
* 参考组装代码
68+
* <pre>
69+
* <code>
70+
* // 使用 HashMap 构建数据结构
71+
* Map<String, Object> data1 = new HashMap<>();
72+
* // 内层字段
73+
* Map<String, String> thing1 = new HashMap<>();
74+
* Map<String, String> thing2 = new HashMap<>();
75+
* Map<String, String> time1 = new HashMap<>();
76+
* Map<String, String> character_string1 = new HashMap<>();
77+
* Map<String, String> time2 = new HashMap<>();
78+
* thing1.put("value", "高和蓝枫箱体测试");
79+
* thing2.put("value", "门口全英测试");
80+
* time1.put("value", "2026年11月23日 19:19");
81+
* character_string1.put("value", "50kg");
82+
* time2.put("value", "2026年11月23日 19:19");
83+
*
84+
* // 模板消息变量,有顺序要求
85+
* Map<String, Object> dataContent = new LinkedHashMap<>();
86+
* dataContent.put("thing1", thing1);
87+
* dataContent.put("thing2", thing2);
88+
* dataContent.put("time1", time1);
89+
* dataContent.put("character_string1", character_string1);
90+
* dataContent.put("time2", time2);
91+
*
92+
* data1.put("data", dataContent);
93+
* </code>
5394
* </pre>
5495
*/
55-
@SerializedName("msg")
56-
private String msg;
96+
97+
@SerializedName("data")
98+
private String data;
5799

58100
public String toJson() {
59101
return WxMaGsonBuilder.create().toJson(this);

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/employee/WxMaUnbindEmployeeRequest.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
import lombok.NoArgsConstructor;
99

1010
import java.io.Serializable;
11+
import java.util.List;
1112

1213
/**
1314
* 小程序解绑用工关系请求实体
1415
* <p>
15-
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
16+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
1617
* </p>
1718
*
1819
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1920
* created on 2025-12-19
21+
* update on 2026-01-22 15:14:09
2022
*/
2123
@Data
2224
@Builder(builderMethodName = "newBuilder")
@@ -27,23 +29,13 @@ public class WxMaUnbindEmployeeRequest implements Serializable {
2729

2830
/**
2931
* <pre>
30-
* 字段名:用户openid
32+
* 字段名:用户openid列表
3133
* 是否必填:是
32-
* 描述:需要解绑的用户openid
34+
* 描述:需要解绑的用户openid列表
3335
* </pre>
3436
*/
35-
@SerializedName("openid")
36-
private String openid;
37-
38-
/**
39-
* <pre>
40-
* 字段名:企业id
41-
* 是否必填:是
42-
* 描述:企业id,小程序管理员在微信开放平台配置
43-
* </pre>
44-
*/
45-
@SerializedName("corp_id")
46-
private String corpId;
37+
@SerializedName("openid_list")
38+
private List<String> openidList;
4739

4840
public String toJson() {
4941
return WxMaGsonBuilder.create().toJson(this);

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,16 @@ public interface Complaint {
10061006
String UPLOAD_RESPONSE_IMAGE_URL = "https://api.weixin.qq.com/cgi-bin/miniapp/complaint/upload";
10071007
}
10081008

1009-
/** 用工关系 */
1009+
/**
1010+
* 小程序用工关系接口
1011+
* <pre>
1012+
* 文档地址: https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/
1013+
* </pre>
1014+
*/
10101015
public interface Employee {
10111016
/** 解绑用工关系 */
1012-
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/unbinduserb2cauthinfo";
1017+
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/business/unbinduserb2cauthinfo";
10131018
/** 推送用工消息 */
1014-
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/wxa/sendemployeerelationmsg";
1019+
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/employeerelationmsg/send";
10151020
}
10161021
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaService;
4+
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
5+
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
6+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
7+
import cn.binarywang.wx.miniapp.test.ApiTestModule;
8+
import com.google.inject.Inject;
9+
import lombok.extern.slf4j.Slf4j;
10+
import me.chanjar.weixin.common.error.WxErrorException;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.testng.annotations.Guice;
13+
import org.testng.annotations.Test;
14+
15+
import java.util.*;
16+
17+
@Slf4j
18+
@Test
19+
@Guice(modules = ApiTestModule.class)
20+
public class WxMaEmployeeRelationServiceImplTest {
21+
22+
@Inject
23+
protected WxMaService wxService;
24+
25+
@Test
26+
public void testSendEmployeeMsg() throws WxErrorException {
27+
WxMaSendEmployeeMsgRequest wxMaSendEmployeeMsgRequest = new WxMaSendEmployeeMsgRequest();
28+
wxMaSendEmployeeMsgRequest.setPage("/pages/index/index");
29+
wxMaSendEmployeeMsgRequest.setTouser("o0uBr12b1zdgCk1qDoBivmSYb9GA");
30+
wxMaSendEmployeeMsgRequest.setTemplateId("nmO-O4V33TOREVLAlumwPCsHssqkt7mea_cyWNE-IFmZqT9jh_LsERhzDOsOqa-3");
31+
32+
// 使用 HashMap 构建数据结构
33+
Map<String, Object> data1 = new HashMap<>();
34+
// 内层字段
35+
Map<String, Object> dataContent = getStringObjectMap();
36+
37+
data1.put("data", dataContent);
38+
wxMaSendEmployeeMsgRequest.setData(WxMaGsonBuilder.create().toJson(data1));
39+
this.wxService.getEmployeeRelationService().sendEmployeeMsg(wxMaSendEmployeeMsgRequest);
40+
}
41+
42+
@NotNull
43+
private static Map<String, Object> getStringObjectMap() {
44+
Map<String, String> thing1 = new HashMap<>();
45+
Map<String, String> thing2 = new HashMap<>();
46+
Map<String, String> time1 = new HashMap<>();
47+
Map<String, String> character_string1 = new HashMap<>();
48+
Map<String, String> time2 = new HashMap<>();
49+
thing1.put("value", "高和蓝枫箱体测试");
50+
thing2.put("value", "门口全英测试");
51+
time1.put("value", "2026年11月23日 19:19");
52+
character_string1.put("value", "50kg");
53+
time2.put("value", "2026年11月23日 19:19");
54+
55+
// 模板消息变量,有顺序要求
56+
Map<String, Object> dataContent = new LinkedHashMap<>();
57+
dataContent.put("thing1", thing1);
58+
dataContent.put("thing2", thing2);
59+
dataContent.put("time1", time1);
60+
dataContent.put("character_string1", character_string1);
61+
dataContent.put("time2", time2);
62+
return dataContent;
63+
}
64+
65+
66+
@Test
67+
public void testUnbinduserb2cauthinfo() throws WxErrorException {
68+
WxMaUnbindEmployeeRequest wxMaUnbindEmployeeRequest = new WxMaUnbindEmployeeRequest();
69+
wxMaUnbindEmployeeRequest.setOpenidList(List.of("o0uBr12b1zdgCk1qDoBivmSYb9GA"));
70+
this.wxService.getEmployeeRelationService().unbindEmployee(wxMaUnbindEmployeeRequest);
71+
}
72+
73+
}

0 commit comments

Comments
 (0)