1
0
mirror of synced 2025-12-21 16:38:01 +08:00

实现小程序用工关系功能

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-19 17:25:47 +00:00
parent 3516bfbc8d
commit fcaaaa6bb6
7 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序用工关系相关操作接口
* <p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html">用工关系简介</a>
* </p>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
*/
public interface WxMaEmployeeRelationService {
/**
* 解绑用工关系
* <p>
* 企业可以调用该接口解除和用户的B2C用工关系
* </p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
*
* @param request 解绑请求参数
* @throws WxErrorException 调用微信接口失败时抛出
*/
void unbindEmployee(WxMaUnbindEmployeeRequest request) throws WxErrorException;
/**
* 推送用工消息
* <p>
* 企业可以调用该接口向用户推送用工相关消息
* </p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
*
* @param request 推送消息请求参数
* @throws WxErrorException 调用微信接口失败时抛出
*/
void sendEmployeeMsg(WxMaSendEmployeeMsgRequest request) throws WxErrorException;
}

View File

@@ -621,4 +621,13 @@ public interface WxMaService extends WxService {
* @return 交易投诉服务对象WxMaComplaintService
*/
WxMaComplaintService getComplaintService();
/**
* 获取用工关系服务对象。
* <br>
* 文档https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
*
* @return 用工关系服务对象WxMaEmployeeRelationService
*/
WxMaEmployeeRelationService getEmployeeRelationService();
}

View File

@@ -167,6 +167,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
private final WxMaIntracityService intracityService = new WxMaIntracityServiceImpl(this);
private final WxMaComplaintService complaintService = new WxMaComplaintServiceImpl(this);
private final WxMaEmployeeRelationService employeeRelationService =
new WxMaEmployeeRelationServiceImpl(this);
private Map<String, WxMaConfig> configMap = new HashMap<>();
private int retrySleepMillis = 1000;
@@ -1048,4 +1050,9 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
public WxMaComplaintService getComplaintService() {
return this.complaintService;
}
@Override
public WxMaEmployeeRelationService getEmployeeRelationService() {
return this.employeeRelationService;
}
}

View File

@@ -0,0 +1,32 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaEmployeeRelationService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.SEND_EMPLOYEE_MSG_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.UNBIND_EMPLOYEE_URL;
/**
* 小程序用工关系相关操作接口实现
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
*/
@RequiredArgsConstructor
public class WxMaEmployeeRelationServiceImpl implements WxMaEmployeeRelationService {
private final WxMaService service;
@Override
public void unbindEmployee(WxMaUnbindEmployeeRequest request) throws WxErrorException {
this.service.post(UNBIND_EMPLOYEE_URL, request.toJson());
}
@Override
public void sendEmployeeMsg(WxMaSendEmployeeMsgRequest request) throws WxErrorException {
this.service.post(SEND_EMPLOYEE_MSG_URL, request.toJson());
}
}

View File

@@ -0,0 +1,61 @@
package cn.binarywang.wx.miniapp.bean.employee;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 小程序推送用工消息请求实体
* <p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
* </p>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
*/
@Data
@Builder(builderMethodName = "newBuilder")
@NoArgsConstructor
@AllArgsConstructor
public class WxMaSendEmployeeMsgRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* <pre>
* 字段名用户openid
* 是否必填:是
* 描述需要接收消息的用户openid
* </pre>
*/
@SerializedName("openid")
private String openid;
/**
* <pre>
* 字段名企业id
* 是否必填:是
* 描述企业id小程序管理员在微信开放平台配置
* </pre>
*/
@SerializedName("corp_id")
private String corpId;
/**
* <pre>
* 字段名:消息内容
* 是否必填:是
* 描述推送的消息内容文本格式最长不超过200个字符
* </pre>
*/
@SerializedName("msg")
private String msg;
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}

View File

@@ -0,0 +1,51 @@
package cn.binarywang.wx.miniapp.bean.employee;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 小程序解绑用工关系请求实体
* <p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
* </p>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
*/
@Data
@Builder(builderMethodName = "newBuilder")
@NoArgsConstructor
@AllArgsConstructor
public class WxMaUnbindEmployeeRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* <pre>
* 字段名用户openid
* 是否必填:是
* 描述需要解绑的用户openid
* </pre>
*/
@SerializedName("openid")
private String openid;
/**
* <pre>
* 字段名企业id
* 是否必填:是
* 描述企业id小程序管理员在微信开放平台配置
* </pre>
*/
@SerializedName("corp_id")
private String corpId;
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}

View File

@@ -996,4 +996,12 @@ public class WxMaApiUrlConstants {
/** 上传反馈图片 */
String UPLOAD_RESPONSE_IMAGE_URL = "https://api.weixin.qq.com/cgi-bin/miniapp/complaint/upload";
}
/** 用工关系 */
public interface Employee {
/** 解绑用工关系 */
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/unbinduserb2cauthinfo";
/** 推送用工消息 */
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/wxa/sendemployeerelationmsg";
}
}