Skip to content

Commit 621b8dc

Browse files
authored
🆕 #3812 【小程序】实现用工关系API支持
1 parent 58cdef9 commit 621b8dc

File tree

7 files changed

+209
-0
lines changed

7 files changed

+209
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
4+
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
5+
import me.chanjar.weixin.common.error.WxErrorException;
6+
7+
/**
8+
* 小程序用工关系相关操作接口
9+
* <p>
10+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html">用工关系简介</a>
11+
* </p>
12+
*
13+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
14+
* created on 2025-12-19
15+
*/
16+
public interface WxMaEmployeeRelationService {
17+
18+
/**
19+
* 解绑用工关系
20+
* <p>
21+
* 企业可以调用该接口解除和用户的B2C用工关系
22+
* </p>
23+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
24+
*
25+
* @param request 解绑请求参数
26+
* @throws WxErrorException 调用微信接口失败时抛出
27+
*/
28+
void unbindEmployee(WxMaUnbindEmployeeRequest request) throws WxErrorException;
29+
30+
/**
31+
* 推送用工消息
32+
* <p>
33+
* 企业可以调用该接口向用户推送用工相关消息
34+
* </p>
35+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
36+
*
37+
* @param request 推送消息请求参数
38+
* @throws WxErrorException 调用微信接口失败时抛出
39+
*/
40+
void sendEmployeeMsg(WxMaSendEmployeeMsgRequest request) throws WxErrorException;
41+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,13 @@ WxMaApiResponse execute(
621621
* @return 交易投诉服务对象WxMaComplaintService
622622
*/
623623
WxMaComplaintService getComplaintService();
624+
625+
/**
626+
* 获取用工关系服务对象。
627+
* <br>
628+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
629+
*
630+
* @return 用工关系服务对象WxMaEmployeeRelationService
631+
*/
632+
WxMaEmployeeRelationService getEmployeeRelationService();
624633
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
167167
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
168168
private final WxMaIntracityService intracityService = new WxMaIntracityServiceImpl(this);
169169
private final WxMaComplaintService complaintService = new WxMaComplaintServiceImpl(this);
170+
private final WxMaEmployeeRelationService employeeRelationService =
171+
new WxMaEmployeeRelationServiceImpl(this);
170172

171173
private Map<String, WxMaConfig> configMap = new HashMap<>();
172174
private int retrySleepMillis = 1000;
@@ -1048,4 +1050,9 @@ public WxMaIntracityService getIntracityService() {
10481050
public WxMaComplaintService getComplaintService() {
10491051
return this.complaintService;
10501052
}
1053+
1054+
@Override
1055+
public WxMaEmployeeRelationService getEmployeeRelationService() {
1056+
return this.employeeRelationService;
1057+
}
10511058
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaEmployeeRelationService;
4+
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
6+
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
7+
import lombok.RequiredArgsConstructor;
8+
import me.chanjar.weixin.common.error.WxErrorException;
9+
10+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.SEND_EMPLOYEE_MSG_URL;
11+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.UNBIND_EMPLOYEE_URL;
12+
13+
/**
14+
* 小程序用工关系相关操作接口实现
15+
*
16+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
17+
* created on 2025-12-19
18+
*/
19+
@RequiredArgsConstructor
20+
public class WxMaEmployeeRelationServiceImpl implements WxMaEmployeeRelationService {
21+
private final WxMaService service;
22+
23+
@Override
24+
public void unbindEmployee(WxMaUnbindEmployeeRequest request) throws WxErrorException {
25+
this.service.post(UNBIND_EMPLOYEE_URL, request.toJson());
26+
}
27+
28+
@Override
29+
public void sendEmployeeMsg(WxMaSendEmployeeMsgRequest request) throws WxErrorException {
30+
this.service.post(SEND_EMPLOYEE_MSG_URL, request.toJson());
31+
}
32+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package cn.binarywang.wx.miniapp.bean.employee;
2+
3+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* 小程序推送用工消息请求实体
14+
* <p>
15+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
16+
* </p>
17+
*
18+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
19+
* created on 2025-12-19
20+
*/
21+
@Data
22+
@Builder(builderMethodName = "newBuilder")
23+
@NoArgsConstructor
24+
@AllArgsConstructor
25+
public class WxMaSendEmployeeMsgRequest implements Serializable {
26+
private static final long serialVersionUID = 1L;
27+
28+
/**
29+
* <pre>
30+
* 字段名:用户openid
31+
* 是否必填:是
32+
* 描述:需要接收消息的用户openid
33+
* </pre>
34+
*/
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;
47+
48+
/**
49+
* <pre>
50+
* 字段名:消息内容
51+
* 是否必填:是
52+
* 描述:推送的消息内容,文本格式,最长不超过200个字符
53+
* </pre>
54+
*/
55+
@SerializedName("msg")
56+
private String msg;
57+
58+
public String toJson() {
59+
return WxMaGsonBuilder.create().toJson(this);
60+
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cn.binarywang.wx.miniapp.bean.employee;
2+
3+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* 小程序解绑用工关系请求实体
14+
* <p>
15+
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
16+
* </p>
17+
*
18+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
19+
* created on 2025-12-19
20+
*/
21+
@Data
22+
@Builder(builderMethodName = "newBuilder")
23+
@NoArgsConstructor
24+
@AllArgsConstructor
25+
public class WxMaUnbindEmployeeRequest implements Serializable {
26+
private static final long serialVersionUID = 1L;
27+
28+
/**
29+
* <pre>
30+
* 字段名:用户openid
31+
* 是否必填:是
32+
* 描述:需要解绑的用户openid
33+
* </pre>
34+
*/
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;
47+
48+
public String toJson() {
49+
return WxMaGsonBuilder.create().toJson(this);
50+
}
51+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,12 @@ public interface Complaint {
997997
/** 上传反馈图片 */
998998
String UPLOAD_RESPONSE_IMAGE_URL = "https://api.weixin.qq.com/cgi-bin/miniapp/complaint/upload";
999999
}
1000+
1001+
/** 用工关系 */
1002+
public interface Employee {
1003+
/** 解绑用工关系 */
1004+
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/unbinduserb2cauthinfo";
1005+
/** 推送用工消息 */
1006+
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/wxa/sendemployeerelationmsg";
1007+
}
10001008
}

0 commit comments

Comments
 (0)