1
0
mirror of synced 2026-02-04 16:40:54 +08:00

🎨 #3808 【小程序】修复用工关系接口地址以及请求实体类字段错误的问题

This commit is contained in:
yclnycl
2026-01-23 16:55:19 +08:00
committed by GitHub
parent a23429c144
commit 5e09c3e968
6 changed files with 145 additions and 31 deletions

View File

@@ -625,7 +625,8 @@ public interface WxMaService extends WxService {
/**
* 获取用工关系服务对象。
* <br>
* 文档https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
* 服务端api文档https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/
* 整体流程文档: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
*
* @return 用工关系服务对象WxMaEmployeeRelationService
*/

View File

@@ -15,6 +15,7 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.UNB
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
* update on 2026-01-22 15:06:33
*/
@RequiredArgsConstructor
public class WxMaEmployeeRelationServiceImpl implements WxMaEmployeeRelationService {

View File

@@ -12,11 +12,12 @@ import java.io.Serializable;
/**
* 小程序推送用工消息请求实体
* <p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/api_sendemployeerelationmsg.html">推送用工消息</a>
* </p>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
* update on 2026-01-22 15:13:28
*/
@Data
@Builder(builderMethodName = "newBuilder")
@@ -27,33 +28,74 @@ public class WxMaSendEmployeeMsgRequest implements Serializable {
/**
* <pre>
* 字段名:用户openid
* 字段名:模板id
* 是否必填:是
* 描述:需要接收消息的用户openid
* 描述:需要在微信后台申请用工关系权限,通过后创建的模板审核通过后可以复制模板ID
* </pre>
*/
@SerializedName("openid")
private String openid;
@SerializedName("template_id")
private String templateId;
/**
* <pre>
* 字段名:企业id
* 字段名:页面
* 是否必填:是
* 描述:企业id小程序管理员在微信开放平台配置
* 描述:用工消息通知跳转的page小程序链接(注意 小程序页面链接要是申请模板的小程序)
* </pre>
*/
@SerializedName("corp_id")
private String corpId;
@SerializedName("page")
private String page;
/**
* <pre>
* 字段名被推送用户的openId
* 是否必填:是
* 描述被推送用户的openId
* </pre>
*/
@SerializedName("touser")
private String touser;
/**
* <pre>
* 字段名:消息内容
* 是否必填:是
* 描述:推送的消息内容文本格式最长不超过200个字符
* 描述:需要根据小程序后台审核通过的模板id的字段类型序列化json传递
*
* </pre>
*
* 参考组装代码
* <pre>
* <code>
* // 使用 HashMap 构建数据结构
* Map<String, Object> data1 = new HashMap<>();
* // 内层字段
* Map<String, String> thing1 = new HashMap<>();
* Map<String, String> thing2 = new HashMap<>();
* Map<String, String> time1 = new HashMap<>();
* Map<String, String> character_string1 = new HashMap<>();
* Map<String, String> time2 = new HashMap<>();
* thing1.put("value", "高和蓝枫箱体测试");
* thing2.put("value", "门口全英测试");
* time1.put("value", "2026年11月23日 19:19");
* character_string1.put("value", "50kg");
* time2.put("value", "2026年11月23日 19:19");
*
* // 模板消息变量,有顺序要求
* Map<String, Object> dataContent = new LinkedHashMap<>();
* dataContent.put("thing1", thing1);
* dataContent.put("thing2", thing2);
* dataContent.put("time1", time1);
* dataContent.put("character_string1", character_string1);
* dataContent.put("time2", time2);
*
* data1.put("data", dataContent);
* </code>
* </pre>
*/
@SerializedName("msg")
private String msg;
@SerializedName("data")
private String data;
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);

View File

@@ -8,15 +8,17 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 小程序解绑用工关系请求实体
* <p>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/api_unbinduserb2cauthinfo.html">解绑用工关系</a>
* </p>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
* update on 2026-01-22 15:14:09
*/
@Data
@Builder(builderMethodName = "newBuilder")
@@ -27,23 +29,13 @@ public class WxMaUnbindEmployeeRequest implements Serializable {
/**
* <pre>
* 字段名用户openid
* 字段名用户openid列表
* 是否必填:是
* 描述需要解绑的用户openid
* 描述需要解绑的用户openid列表
* </pre>
*/
@SerializedName("openid")
private String openid;
/**
* <pre>
* 字段名企业id
* 是否必填:是
* 描述企业id小程序管理员在微信开放平台配置
* </pre>
*/
@SerializedName("corp_id")
private String corpId;
@SerializedName("openid_list")
private List<String> openidList;
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);

View File

@@ -1006,11 +1006,16 @@ public class WxMaApiUrlConstants {
String UPLOAD_RESPONSE_IMAGE_URL = "https://api.weixin.qq.com/cgi-bin/miniapp/complaint/upload";
}
/** 用工关系 */
/**
* 小程序用工关系接口
* <pre>
* 文档地址: https://developers.weixin.qq.com/miniprogram/dev/server/API/laboruse/
* </pre>
*/
public interface Employee {
/** 解绑用工关系 */
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/unbinduserb2cauthinfo";
String UNBIND_EMPLOYEE_URL = "https://api.weixin.qq.com/wxa/business/unbinduserb2cauthinfo";
/** 推送用工消息 */
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/wxa/sendemployeerelationmsg";
String SEND_EMPLOYEE_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/employeerelationmsg/send";
}
}

View File

@@ -0,0 +1,73 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.*;
@Slf4j
@Test
@Guice(modules = ApiTestModule.class)
public class WxMaEmployeeRelationServiceImplTest {
@Inject
protected WxMaService wxService;
@Test
public void testSendEmployeeMsg() throws WxErrorException {
WxMaSendEmployeeMsgRequest wxMaSendEmployeeMsgRequest = new WxMaSendEmployeeMsgRequest();
wxMaSendEmployeeMsgRequest.setPage("/pages/index/index");
wxMaSendEmployeeMsgRequest.setTouser("o0uBr12b1zdgCk1qDoBivmSYb9GA");
wxMaSendEmployeeMsgRequest.setTemplateId("nmO-O4V33TOREVLAlumwPCsHssqkt7mea_cyWNE-IFmZqT9jh_LsERhzDOsOqa-3");
// 使用 HashMap 构建数据结构
Map<String, Object> data1 = new HashMap<>();
// 内层字段
Map<String, Object> dataContent = getStringObjectMap();
data1.put("data", dataContent);
wxMaSendEmployeeMsgRequest.setData(WxMaGsonBuilder.create().toJson(data1));
this.wxService.getEmployeeRelationService().sendEmployeeMsg(wxMaSendEmployeeMsgRequest);
}
@NotNull
private static Map<String, Object> getStringObjectMap() {
Map<String, String> thing1 = new HashMap<>();
Map<String, String> thing2 = new HashMap<>();
Map<String, String> time1 = new HashMap<>();
Map<String, String> character_string1 = new HashMap<>();
Map<String, String> time2 = new HashMap<>();
thing1.put("value", "高和蓝枫箱体测试");
thing2.put("value", "门口全英测试");
time1.put("value", "2026年11月23日 19:19");
character_string1.put("value", "50kg");
time2.put("value", "2026年11月23日 19:19");
// 模板消息变量,有顺序要求
Map<String, Object> dataContent = new LinkedHashMap<>();
dataContent.put("thing1", thing1);
dataContent.put("thing2", thing2);
dataContent.put("time1", time1);
dataContent.put("character_string1", character_string1);
dataContent.put("time2", time2);
return dataContent;
}
@Test
public void testUnbinduserb2cauthinfo() throws WxErrorException {
WxMaUnbindEmployeeRequest wxMaUnbindEmployeeRequest = new WxMaUnbindEmployeeRequest();
wxMaUnbindEmployeeRequest.setOpenidList(List.of("o0uBr12b1zdgCk1qDoBivmSYb9GA"));
this.wxService.getEmployeeRelationService().unbindEmployee(wxMaUnbindEmployeeRequest);
}
}