repo stringclasses 1k values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 6 values | commit_sha stringclasses 1k values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/user/JwUserAPI.java | src/main/java/com/jeecg/qywx/api/user/JwUserAPI.java | package com.jeecg.qywx.api.user;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.user.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 企业微信--yqj
*
* @author yqj
*
*/
public class JwUserAPI {
private static final Logger logger = LoggerFactory.getLogger(JwUserAPI.class);
//1 创建成员
private static String user_create_url = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN";
//2 更新成员
private static String user_update_url = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=ACCESS_TOKEN";
//3 删除成员
private static String user_delete_url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=USERID";
//4 批量删除成员
private static String user_delete_all_url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN";
//5 获取成员
private static String user_get_url_byuserid = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID";
//6 获取部门下的成员
private static String user_get_dep_all_url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD&status=STATUS";
//7 获取部门成员(详情)
private static String user_get_url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD&status=STATUS";
//8 手机号获取userid
private static String user_get_userid = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=ACCESS_TOKEN";
//9 根据网页授权登录获取到的code来获取用户详情
private static String user_get_userinfo = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=CODE&access_token=ACCESS_TOKEN";
// 获取企业成员的userid与对应的部门ID列表
private static String user_get_id_list = "https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=ACCESS_TOKEN";
//1创建成员
/**
* 创建成员
* @param user 用户实例
* 参数 必须 说明
* access_token 是 调用接口凭证
* userid 是 成员UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字节
* name 是 成员名称。长度为1~64个字节
* department 否 成员所属部门id列表
* position 否 职位信息。长度为0~64个字节
* mobile 否 手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空
* gender 否 性别。1表示男性,2表示女性
* email 否 邮箱。长度为0~64个字节。企业内必须唯一
* weixinid 否 微信号。企业内必须唯一。(注意:是微信号,不是微信的名字)
* avatar_mediaid否 成员头像的mediaid,通过多媒体接口上传图片获得的mediaid
* extattr 否 扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int createUser(User user, String accessToken){
int result = 0;
logger.info("[CREATEUSER] createUser param:user:{},accessToken:{}", user,accessToken);
// 拼装获取成员列表的url
String url = user_create_url.replace("ACCESS_TOKEN", accessToken);
// 将成员对象转换成json字符串
String jsonUser = JSONObject.toJSONString(user);
logger.info("[CREATEUSER] createUser param:jsonUser:{}", jsonUser);
// 调用接口创建用户
JSONObject jsonObject = HttpUtil.sendPost(url, jsonUser);
logger.info("[CREATEUSER] createUser response:{}", jsonObject.toJSONString());
// 调用接口创建用户
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
//2更新成员
/**
*
* @param user 用户实例
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int updateUser(User user, String accessToken){
int result=0;
logger.info("[UPDATEUSER] updateUser param:user:{},accessToken:{}", user,accessToken);
// 拼装更新成员列表的url
String url = user_update_url.replace("ACCESS_TOKEN", accessToken);
// 将成员对象转换成json字符串
String jsonUser = JSONObject.toJSONString(user);
logger.info("[UPDATEUSER] updateUser param:jsonUser:{}", jsonUser);
// 调用接口更新用户
JSONObject jsonObject = HttpUtil.sendPost(url, jsonUser);
logger.info("[UPDATEUSER] updateUser response:{}", jsonObject.toJSONString());
// 调用接口更新成员
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
//3删除成员
/**
*
* @param userid 用户成员ID
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int deleteUser(String userid, String accessToken){
int result=0;
logger.info("[DELETEUSER] deleteUser param:userid:{},accessToken:{}", userid,accessToken);
// 拼装删除成员列表的url
String url = user_delete_url.replace("ACCESS_TOKEN", accessToken).replace("USERID", userid);
// 将成员对象转换成json字符串
logger.info("[DELETEUSER] deleteUser param:userid:{}", userid);
// 调用接口删除用户
JSONObject jsonObject = HttpUtil.sendPost(url);
logger.info("[DELETEUSER] deleteUser response:{}", jsonObject.toJSONString());
// 调用接口删除成员
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
//4批量删除成员
/**
* 注意转换
* @param useridlist 所有用户成员ID
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int batchDeleteUsers(String[] useridlist, String accessToken){
int result=0;
logger.info("[BATCHDELETEUSERS] batchDeleteUsers param:useridlist:{},accessToken:{}", useridlist,accessToken);
// 拼装批量删除成员列表的url
String url = user_delete_all_url.replace("ACCESS_TOKEN", accessToken);
// 将成员对象转换成json字符串
Map<String, String[]> paramtermap=new HashMap<String, String[]>();
paramtermap.put("useridlist", useridlist);
String jsonUserids = JSONObject.toJSONString(paramtermap);
logger.info("[BATCHDELETEUSERS] batchDeleteUsers param:useridlist:{}", paramtermap);
// 调用接口批量删除
JSONObject jsonObject = HttpUtil.sendPost(url,jsonUserids);
logger.info("[BATCHDELETEUSERS] batchDeleteUsers response:{}", jsonObject.toJSONString());
// 调用接口批量删除
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
//5获取成员
public static User getUserByUserid(String userid, String accessToken){
logger.info("[GETUSERBYUSERID] getUserByUserid param:userid:{},accessToken:{}", userid,accessToken);
// 拼装获取成员的url
String url = user_get_url_byuserid.replace("ACCESS_TOKEN", accessToken).replace("USERID", userid);
// 调用接口获取成员
JSONObject jsonObject = HttpUtil.sendPost(url);
logger.info("[GETUSERBYUSERID] getUserByUserid response:{}", jsonObject.toJSONString());
//把对象转换成user
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(errcode==0){
User user = JSONObject.toJavaObject(jsonObject, User.class);
return user;
}
}
return null;
}
//6获取部门成员
public static List<User> getUsersByDepartid(String department_id,String fetch_child,String status , String accessToken){
logger.info("[GETUSERSBYDEPARTID] getUsersByDepartid param:department_id:{},fetch_child:{},status:{},accessToken:{}", department_id,fetch_child,status,accessToken);
// 拼装获取部门成员的列表的url
String url = user_get_dep_all_url.replace("ACCESS_TOKEN", accessToken).replace("DEPARTMENT_ID", department_id);
if(fetch_child!=null){
url = url.replace("FETCH_CHILD", fetch_child);
}
if(status!=null){
url = url.replace("STATUS", status);
}
// 调用接口获取部门成员
JSONObject jsonObject = HttpUtil.sendPost(url);
logger.info("[GETUSERSBYDEPARTID] getUsersByDepartid response:{}", jsonObject.toJSONString());
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(errcode==0){
// List<User> users = JSONArray.toJavaObject(jsonObject.getJSONArray("userlist"), List.class);
// List<Object> users =jsonObject.getJSONArray("userlist");
List<User> users = JSON.parseArray(jsonObject.getString("userlist"),User.class);
return users;
}
}
return null;
}
//7 获取部门成员(详情)
@Deprecated
public static List<User> getDetailUsersByDepartid(String department_id,String fetch_child,String status , String accessToken){
if(null==fetch_child){
// fetch_child="";
fetch_child="1";
}
if(null==status){
// status="";
status="0";
}
logger.info("[GETDETAILUSERSBYDEPARTID] getDetailUsersByDepartid param:department_id:{},fetch_child:{},status:{},accessToken:{}", department_id,fetch_child,status,accessToken);
// 拼装获取部门成员(详情)的列表的url
String url = user_get_url.replace("ACCESS_TOKEN", accessToken).replace("DEPARTMENT_ID", department_id).replace("FETCH_CHILD", fetch_child).replace("STATUS", status);
// 调用接口获取部门成员(详情)
JSONObject jsonObject = HttpUtil.sendPost(url);
// System.out.println("jsonObject="+jsonObject);
logger.info("[GETDETAILUSERSBYDEPARTID] getDetailUsersByDepartid response:{}", jsonObject.toJSONString());
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(errcode==0){
// List<User> users = JSONArray.toJavaObject(jsonObject.getJSONArray("userlist"), List.class);
// return users;
List<User> users = JSON.parseArray(jsonObject.getString("userlist"),User.class);
return users;
}
}
return null;
}
//8 手机号获取userid
public static String getUserIdByPhone(String phone, String accessToken) {
logger.info("[GETUSERIDBYPHONE] getUserIdByPhone param:phone:{},accessToken:{}", phone, accessToken);
JSONObject params = new JSONObject();
params.put("mobile", phone);
String url = user_get_userid.replace("ACCESS_TOKEN", accessToken);
JSONObject response = HttpUtil.sendPost(url, params.toJSONString());
if (response != null) {
int errcode = response.getIntValue("errcode");
if (errcode == 0) {
return response.getString("userid");
}
}
return null;
}
/**
* 9 根据网页授权登录获取到的code来获取用户详情
*
* @param code
* @param accessToken
* @return
*/
public static JSONObject getUserInfoByCode(String code, String accessToken) {
logger.info("[GETUSERINFOBYCODE] getUserInfoByCode param:code:{},accessToken:{}", code, accessToken);
String url = user_get_userinfo.replace("CODE", code).replace("ACCESS_TOKEN", accessToken);
// errcode
return HttpUtil.sendGet(url);
}
/**
* 10 获取企业成员的userid与对应的部门ID列表
*
* @param accessToken 调用接口凭证
*/
public static List<User> getUserIdList(String accessToken) {
logger.info("[GETUSERIDLIST] getUserIdList params:accessToken:{}", accessToken);
String url = user_get_id_list.replace("ACCESS_TOKEN", accessToken);
JSONObject response = HttpUtil.sendPost(url);
if (response != null) {
logger.info("[GETUSERIDLIST] getUserIdList response:{}", response.toJSONString());
int errcode = response.getIntValue("errcode");
if (errcode == 0) {
JSONArray deptUser = response.getJSONArray("dept_user");
List<User> users = new ArrayList<>();
for (int i = 0; i < deptUser.size(); i++) {
JSONObject user = deptUser.getJSONObject(i);
User u = new User();
u.setUserid(user.getString("userid"));
int department = user.getIntValue("department");
u.setDepartment(new Integer[]{department});
users.add(u);
}
return users;
}
} else {
logger.info("[GETUSERIDLIST] getUserIdList response: null");
}
return null;
}
public static void main(String[] args) {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
/*JSONObject js = getUsersByDepartid("5", null,null,accessToken.getAccesstoken());
System.out.println(js.toJSONString());*/
//1:测试创建成员
/*User user=new User();
user.setUserid("yangmoumou1");
user.setName("杨某某1");
user.setPosition("JAVA测试人员");
user.setMobile("13880981678");//电话号码必须要
user.setDepartment(new Integer[]{5});//设置部门
int result = createUser(user, accessToken.getAccesstoken());
System.out.println(result==0?"成功":"失败"+"----"+result);
*
*/
/*User user=new User();
user.setUserid("yangmoumou3");
user.setName("杨某某2");
user.setPosition("JAVA测试人员");
user.setMobile("13880981672");//电话号码必须要
user.setDepartment(new Integer[]{5});//设置部门
int result = createUser(user, accessToken.getAccesstoken());
System.out.println(result==0?"成功":"失败"+"----"+result);*/
//2:updateUser
/*User user=new User();
user.setUserid("yangmoumou1");
user.setName("杨某某修改后");
user.setPosition("JAVA测试人员333");
user.setMobile("13880981678");//电话号码必须要
user.setDepartment(new Integer[]{5});//设置部门
int result = updateUser(user, accessToken.getAccesstoken());
System.out.println(result==0?"修改成功":"失败"+"----"+result);*/
//3:deleteUser
/*int result=deleteUser("yangmoumou1", accessToken.getAccesstoken());//测试删除
System.out.println(result==0?"删除成功":"失败"+"----"+result);*/
/*
* 4:batchDeleteUsers
int result = batchDeleteUsers(new String[]{"yangmoumou3"}, accessToken.getAccesstoken());
System.out.println(result==0?"删除成功":"失败"+"----"+result);*/
/**
* 5:getUserByUserid
*/
// User user = getUserByUserid("yangqj", accessToken.getAccesstoken());
// System.out.println(JSONObject.toJSON(user));
/**
*6 getUsersByDepartid
*/
/*List<User> users=getUsersByDepartid("5", null, null, accessToken.getAccesstoken());
for (User user : users) {
System.out.println("xx");
}
System.out.println(JSONObject.toJSON(users));*/
/**
* 7 获取部门成员(详情)
*/
/*List<User> users=getDetailUsersByDepartid("5", null, null, accessToken.getAccesstoken());
System.out.println(JSONObject.toJSON(users));*/
/*
* 7 获取成员id
*/
List<User> users = JwUserAPI.getUserIdList(accessToken.getAccesstoken());
System.out.println(JSON.toJSONString(users));
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/user/vo/User.java | src/main/java/com/jeecg/qywx/api/user/vo/User.java | package com.jeecg.qywx.api.user.vo;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
/**
*
* @author Yqj
* 企业微信--user
*
*/
public class User {
private String userid;//成员UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字节
private String name;//成员名称。长度为1~64个字节
private Integer[] department;//成员所属部门id列表
private String position;//职位信息。长度为0~64个字节
private String mobile;//手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空 创建时必须要
private String gender;//性别。1表示男性,2表示女性
private String email;//邮箱。长度为0~64个字节。企业内必须唯一
private String weixinid;//微信号。企业内必须唯一。(注意:是微信号,不是微信的名字)
// @JSONField(serialize=false)
private Integer enable;//启用/禁用成员。1表示启用成员,0表示禁用成员
private String avatar_mediaid;//成员头像的mediaid,通过多媒体接口上传图片获得的mediaid
// @JSONField(serialize=false)
private String avatar;//头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可 创建的时候不需要这个字段 也可以使用transient来取消序列化
// @JSONField(serialize=false)
private Integer status;//关注状态 1=已关注,2=已禁用,4=未关注 创建的时候不需要这个字段 也可以使用transient来取消序列化
private String telephone; // 座机号
private Integer[] is_leader_in_dept; // 个数必须和参数department的个数一致,表示在所在的部门内是否为上级。1表示为上级,0表示非上级。在审批等应用里可以用来标识上级审批人
private JSONObject extattr;//扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer[] getDepartment() {
return department;
}
public void setDepartment(Integer[] department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWeixinid() {
return weixinid;
}
public void setWeixinid(String weixinid) {
this.weixinid = weixinid;
}
public Integer getEnable() {
return enable;
}
public void setEnable(Integer enable) {
this.enable = enable;
}
public String getAvatar_mediaid() {
return avatar_mediaid;
}
public void setAvatar_mediaid(String avatar_mediaid) {
this.avatar_mediaid = avatar_mediaid;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public JSONObject getExtattr() {
return extattr;
}
public void setExtattr(JSONObject extattr) {
this.extattr = extattr;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Integer[] getIs_leader_in_dept() {
return is_leader_in_dept;
}
public void setIs_leader_in_dept(Integer[] is_leader_in_dept) {
this.is_leader_in_dept = is_leader_in_dept;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java | src/main/java/com/jeecg/qywx/api/department/JwDepartmentAPI.java | package com.jeecg.qywx.api.department;
import java.util.List;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.department.vo.DepartMsgResponse;
import com.jeecg.qywx.api.department.vo.Department;
/**
* 企业微信--管理部门
*
* @author zhoujf
*
*/
public class JwDepartmentAPI {
private static final Logger logger = LoggerFactory.getLogger(JwDepartmentAPI.class);
//创建部门(POST)
private static String department_create_url = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=ACCESS_TOKEN";
//更新部门(POST)
private static String department_update_url = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=ACCESS_TOKEN";
//删除部门(GET)
private static String department_delete_url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=ACCESS_TOKEN&id=ID";
//获取部门列表(GET) [获取特定部门]
private static String department_list_url_get = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=ID";
//获取部门列表(GET) [获取全部组织机构]
private static String department_list_url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN";
/**
* 创建部门
* @param department 部门数据,参见 {@linkplain Department},必须赋值属性如下:
* <ul>
* <li>name 是 部门名称。长度限制为1~64个字节,字符不能包括\:*?"<>|</li>
* <li>parentid 是 父亲部门id。根部门id为1</li>
* <li>order 否 在父部门中的次序值。order值小的排序靠前。</li>
* <li>id 否 部门id,整型。指定时必须大于1,不指定时则自动生成</li>
* </ul>
* @param accessToken 有效的access_token
* @return DepartMsgResponse 响应数据,参见 {@linkplain DepartMsgResponse},必须赋值属性如下:
* <ul>
* <li>errcode 返回码</li>
* <li>errmsg 对返回码的文本描述内容</li>
* <li>id 创建的部门id</li>
* </ul>
*/
public static DepartMsgResponse createDepartment(Department department, String accessToken) {
logger.info("[CREATEDEPARTMENT]", "createDepartment param:accessToken:{},menu:{}", new Object[]{accessToken,department});
DepartMsgResponse res = null;
// 拼装创建部门的url
String url = department_create_url.replace("ACCESS_TOKEN", accessToken);
// 将菜单对象转换成json字符串
String jsonParam = JSONObject.toJSONString(department);
logger.info("[CREATEDEPARTMENT]", "createDepartment param:jsonParam:{}", new Object[]{jsonParam});
// 调用接口创建部门
JSONObject jsonObject = HttpUtil.sendPost(url, jsonParam);
logger.info("[CREATEDEPARTMENT]", "createDepartment response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
res = new DepartMsgResponse();
int errcode = jsonObject.getIntValue("errcode");
String errmsg = jsonObject.getString("errmsg");
System.out.println("errcode:"+errcode+",errmsg:"+errmsg);
res.setErrcode(errcode);
res.setErrmsg(errmsg);
if(errcode==0){
int id = jsonObject.getIntValue("id");
res.setId(id);
}
}
return res;
}
/**
* 获取所有部门
* @param department
* @param accessToken
* @return
*/
public static List<Department> getAllDepartment(String accessToken) {
logger.info("[CREATEDEPARTMENT]", "createDepartment param:accessToken:{},menu:{}", new Object[]{accessToken});
DepartMsgResponse res = null;
// 拼装创建部门的url
String url = department_list_url.replace("ACCESS_TOKEN", accessToken);
// 调用接口创建部门
JSONObject jsonObject = HttpUtil.sendPost(url);
logger.info("[CREATEDEPARTMENT]", "createDepartment response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
String errmsg = jsonObject.getString("errmsg");
String departmentjson = jsonObject.getString("department");
List<Department> ps = JSON.parseArray(departmentjson, Department.class);
return ps;
}
return null;
}
/**
* 获取指定部门
*
* @param depId
* @param accessToken
* @return
*/
public static List<Department> getDepartmentById(String depId, String accessToken) {
logger.info("[JW_DEPARTMENT] getDepartmentById param:accessToken:{}", new Object[]{accessToken});
// 拼装url
String url = department_list_url_get.replace("ACCESS_TOKEN", accessToken).replace("ID", depId);
// 调用接口查询部门
JSONObject response = HttpUtil.sendPost(url);
logger.info("[JW_DEPARTMENT] getDepartmentById response:{}", new Object[]{response.toJSONString()});
return response.getJSONArray("department").toJavaList(Department.class);
}
/**
* 删除部门
* @param departId
* @param accessToken
* @return
*/
public static int deleteDepart(String departId,String accessToken) {
String url = department_delete_url.replace("ACCESS_TOKEN", accessToken).replace("ID", departId);
JSONObject jsonObject = HttpUtil.sendPost(url);
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
String errmsg = jsonObject.getString("errmsg");
System.out.println("errcode:"+errcode+",errmsg:"+errmsg);
return errcode;
}
return -1;
}
/**
* 修改部门
* @param department
* @param accessToken
* @return
*/
public static int updateDepart(Department department,String accessToken) {
String url = department_update_url.replace("ACCESS_TOKEN", accessToken);
String jsonParam = JSONObject.toJSONString(department);
JSONObject jsonObject = HttpUtil.sendPost(url,jsonParam);
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
String errmsg = jsonObject.getString("errmsg");
System.out.println("errcode:"+errcode+",errmsg:"+errmsg);
return errcode;
}
return -1;
}
public static void main(String[] args){
try {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
//查询部门
// List<Department> ls = JwDepartmentAPI.getAllDepartment(accessToken.getAccesstoken());
// for(Department po:ls){
// System.out.println(po.toString());
// }
//删除部门
// JwDepartmentAPI.deleteDepart(7,accessToken.getAccesstoken());
//创建部门
Department department = new Department();
department.setId("cccddd");
department.setName("cccddd");
department.setOrder("2");
department.setParentid("28A874914D2F4082AFCA1201E8B21E5B");
JwDepartmentAPI.createDepartment(department, accessToken.getAccesstoken());
//修改部门
// Department department = new Department();
// department.setId(8);
// department.setName("人力资源1");
// department.setOrder(1);
// department.setParentid(1);
// JwDepartmentAPI.updateDepart(department, accessToken.getAccesstoken());
} catch (Exception e) {
e.printStackTrace();
}
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/department/vo/DepartMsgResponse.java | src/main/java/com/jeecg/qywx/api/department/vo/DepartMsgResponse.java | package com.jeecg.qywx.api.department.vo;
import com.jeecg.qywx.api.core.common.MsgResponse;
public class DepartMsgResponse extends MsgResponse {
private static final long serialVersionUID = -4154816708672985619L;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "DepartMsgResponse [id=" + id + ",errcode=" + this.getErrcode() + ", errmsg=" + this.getErrmsg() +"]";
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/department/vo/Department.java | src/main/java/com/jeecg/qywx/api/department/vo/Department.java | package com.jeecg.qywx.api.department.vo;
import java.io.Serializable;
/**
* 微信部门
*
* @author zhoujf
*/
public class Department implements Serializable {
private static final long serialVersionUID = 6102281663991601498L;
private String id;
private String name;
private String parentid;
private String order;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getParentid() {
return parentid;
}
public void setParentid(String parentid) {
this.parentid = parentid;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
@Override
public String toString() {
return "Department{" +
"id=" + id +
", name='" + name + '\'' +
", parentId=" + parentid +
", order=" + order +
'}';
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/userandopenmsg/JwCardMessageAPI.java | src/main/java/com/jeecg/qywx/api/userandopenmsg/JwCardMessageAPI.java | package com.jeecg.qywx.api.userandopenmsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.user.JwUserAPI;
import com.jeecg.qywx.api.user.vo.User;
import com.jeecg.qywx.api.userandopenmsg.vo.OpenToUser;
import com.jeecg.qywx.api.userandopenmsg.vo.UserToOpen;
public class JwCardMessageAPI {
private static final Logger logger = LoggerFactory.getLogger(JwUserAPI.class);
//userid转换成openid接口
private static String card_userConverOpen_url ="https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=ACCESS_TOKEN";
//openid转换成userid接口
private static String card_openConverUser_url="https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?access_token=ACCESS_TOKEN";
/**
* userid转换成openid接口的api
* @param UserToOpen 用户实例
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int userConverOpen(UserToOpen userToOpen, String accessToken){
int result = 0;
logger.info("[CREATEUSER]", "createUser param:userToOpen:{},accessToken:{}", new Object[]{userToOpen,accessToken});
// 拼装获取成员列表的url
String url = card_userConverOpen_url.replace("ACCESS_TOKEN", accessToken);
// 将成员对象转换成json字符串
String jsonUserTOOpen = JSONObject.toJSONString(userToOpen);
logger.info("[CREATEUSER]", "createUser param:jsonUser:{}", new Object[]{jsonUserTOOpen});
// 调用接口创建用户
JSONObject jsonObject = HttpUtil.sendPost(url, jsonUserTOOpen);
logger.info("[CREATEUSER]", "createUser response:{}", new Object[]{jsonObject.toJSONString()});
// 调用接口创建用户
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/**
* openid转换成userid接口
* @param OpenToUser 用户实例
* @param accessToken 有效的access_token
* @return 0表示成功,其他值表示失败
*/
public static int openConverUser(OpenToUser openToUser, String accessToken){
int result = 0;
logger.info("[CREATEUSER]", "createUser param:openToUser:{},accessToken:{}", new Object[]{openToUser,accessToken});
// 拼装获取成员列表的url
String url = card_userConverOpen_url.replace("ACCESS_TOKEN", accessToken);
// 将成员对象转换成json字符串
String jsonOpenToUser = JSONObject.toJSONString(openToUser);
logger.info("[CREATEUSER]", "createUser param:jsonOpenToUser:{}", new Object[]{jsonOpenToUser});
// 调用接口创建用户
JSONObject jsonObject = HttpUtil.sendPost(url, jsonOpenToUser);
logger.info("[CREATEUSER]", "createUser response:{}", new Object[]{jsonObject.toJSONString()});
// 调用接口创建用户
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
public static void main(String[] args) {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
//测试userConverOpen 测试成功openid=oTFwXt76Y9nRM7itV1WmYS0OJ6WE token=DnwUIQ-4WrhvqoPqMEb9-KCuLmlZAOankR4b2SuVA_DkhT49J1uPI0pNivZ2ohVp
UserToOpen user=new UserToOpen();
user.setAgentid(1);
user.setUserid("malimei");
JwCardMessageAPI.userConverOpen(user, accessToken.getAccesstoken());
//openid转换成userid接口,暂时没有测通过去
/*OpenToUser open=new OpenToUser();
open.setOpenid("oTFwXt76Y9nRM7itV1WmYS0OJ6WE");
String accessToken="DnwUIQ-4WrhvqoPqMEb9-KCuLmlZAOankR4b2SuVA_DkhT49J1uPI0pNivZ2ohVp";
JwCardMessageAPI.openConverUser(open, accessToken);*/
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/userandopenmsg/vo/UserToOpen.java | src/main/java/com/jeecg/qywx/api/userandopenmsg/vo/UserToOpen.java | package com.jeecg.qywx.api.userandopenmsg.vo;
public class UserToOpen {
private String userid;//企业号内的成员id
private int agentid;// 整型,需要发送红包的应用ID,若只是使用微信支付和企业转账,则无需该参数
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/userandopenmsg/vo/OpenToUser.java | src/main/java/com/jeecg/qywx/api/userandopenmsg/vo/OpenToUser.java | package com.jeecg.qywx.api.userandopenmsg.vo;
public class OpenToUser {
private String openid;//在使用微信支付、微信红包和企业转账之后,返回结果的openid
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java | src/main/java/com/jeecg/qywx/api/conversation/ConversationAPI.java | package com.jeecg.qywx.api.conversation;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.conversation.vo.BaseMessage;
import com.jeecg.qywx.api.conversation.vo.Conversation;
import com.jeecg.qywx.api.conversation.vo.Conversation4Update;
import com.jeecg.qywx.api.conversation.vo.Mute;
import com.jeecg.qywx.api.core.common.MsgResponse;
import com.jeecg.qywx.api.core.util.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
*
* @author SunHaiFeng
* 会话API
*/
public class ConversationAPI {
private static final Logger logger = LoggerFactory.getLogger(ConversationAPI.class);
/**创建会话信息URL*/
private static String conversation_create_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/create?access_token=ACCESS_TOKEN";
/**获取会话信息*/
private static String conversation_get_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/get?access_token=ACCESS_TOKEN&chatid=CHATID";
/**修改会话信息*/
private static String conversation_update_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/update?access_token=ACCESS_TOKEN";
/**退出会话*/
private static String conversation_quit_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/quit?access_token=ACCESS_TOKEN";
/**清除未读状态*/
private static String conversation_clearnotifay_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/clearnotify?access_token=ACCESS_TOKEN";
/**发送消息URL*/
private static String conversation_send_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/send?access_token=ACCESS_TOKEN";
/**设置消息*/
private static String conversation_setmute_url = "https://qyapi.weixin.qq.com/cgi-bin/chat/setmute?access_token=ACCESS_TOKEN";
/**
* 创建会话
* @param conversation
* @return
*/
public static MsgResponse createConversation(Conversation conversation,String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result = -1;
logger.info("[CREATECONVERSATION]", "createConversation param:conversation:{},accessToken:{}", new Object[]{conversation,accessToken});
String url = conversation_create_url.replace("ACCESS_TOKEN", accessToken);
String jsonContent = JSONObject.toJSONString(conversation);
logger.info("[CREATECONVERSATION]", "createConversation param:jsonUser:{}", new Object[]{jsonContent});
JSONObject jsonObject = HttpUtil.sendPost(url, jsonContent);
logger.info("[CREATECONVERSATION]", "createConversation response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(jsonObject.containsKey("errmsg")){
errmsg = jsonObject.getString("errmsg");
}
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
return msgResponse;
}
/**
* 获取会话信息
* @param chatid 会话ID
* @param accessToken TOKEN
* @return
*/
public static Conversation getConversation(String chatid, String accessToken){
logger.info("[GETCONVERSATION]", "getConversation param:chatid:{},accessToken:{}", new Object[]{chatid,accessToken});
String url = conversation_get_url.replace("ACCESS_TOKEN", accessToken).replace("CHATID", chatid);
JSONObject jsonObject = HttpUtil.sendPost(url);
logger.info("[GETCONVERSATION]", "getConversation response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(errcode==0){
Conversation conversation = JSONObject.toJavaObject(jsonObject, Conversation.class);
return conversation;
}
}
return null;
}
/**
* 修改会话信息
* @param chatid 会话ID
* @param opUser 操作用户ID
* @param name 修改为会话名称
* @param owner 修改管理员ID
* @param addUserlist 新增会话成员
* @param delUserlist 删除会话成员
* @param accessToken
* @return
*/
public static MsgResponse updateConversation(Conversation4Update converstation, String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result =-1 ;
String jsonContent = JSONObject.toJSONString(converstation);
String url = conversation_update_url.replace("ACCESS_TOKEN", accessToken);
JSONObject jsonObject = HttpUtil.sendPost(url, jsonContent);
try {
if(jsonObject!=null) {
int errcode = jsonObject.getIntValue("errcode");
errmsg = jsonObject.getString("errmsg");
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
} catch (Exception e) {
e.printStackTrace();
}
return msgResponse;
}
/**
* 退出会话
* @param chatid 会话ID
* @param opUser 操作员ID
* @param accessToken
* @return
*/
public static MsgResponse quit(String chatid,String opUser,String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result = -1;
JSONObject jsonContent = new JSONObject();
jsonContent.put("chatid", chatid);
jsonContent.put("op_user", opUser);
String url = conversation_quit_url.replace("ACCESS_TOKEN", accessToken);
JSONObject jsonObject = HttpUtil.sendPost(url, jsonContent.toJSONString());
if(null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(jsonObject.containsKey("errmsg")){
errmsg = jsonObject.getString("errmsg");
}
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
return msgResponse;
}
/**
* 清除会话状态
* @param chatidOrUserid 会话ID或用户ID
* @param type 类型:single或group 即 群聊或单聊
* @param opUser 操作人ID
* @param accessToken
* @return
*/
public static MsgResponse clearnotify(String chatidOrUserid,String type,String opUser,String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result = -1;
JSONObject jsonContent = new JSONObject();
JSONObject chat = new JSONObject();
chat.put("id", chatidOrUserid);
chat.put("type", type);
jsonContent.put("chat", chat);
jsonContent.put("op_user", opUser);
String url = conversation_clearnotifay_url.replace("ACCESS_TOKEN", accessToken);
JSONObject jsonObject = HttpUtil.sendPost(url,jsonContent.toJSONString());
if(null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(jsonObject.containsKey("errmsg")){
errmsg = jsonObject.getString("errmsg");
}
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
return msgResponse;
}
/**
* 会话中发送消息
* @param textMessage 消息对象 发送不同消息,创建不同子类即可
* @param accessToken
* @return
*/
public static MsgResponse sendMessage(BaseMessage message,String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result = -1;
logger.info("[SENDMESSAGE]", "sendMessage param:conversation:{},accessToken:{}", new Object[]{message,accessToken});
String url = conversation_send_url.replace("ACCESS_TOKEN", accessToken);
String jsonContent = JSONObject.toJSONString(message);
logger.info("[SENDMESSAGE]", "sendMessage param:jsonUser:{}", new Object[]{jsonContent});
JSONObject jsonObject = HttpUtil.sendPost(url, jsonContent);
logger.info("[SENDMESSAGE]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if(null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(jsonObject.containsKey("errmsg")){
errmsg = jsonObject.getString("errmsg");
}
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
return msgResponse;
}
/**
* 设置用户消息
* @param userlist
* @param accessToken
* @return
*/
public static MsgResponse setMute(List<Mute> userlist,String accessToken){
MsgResponse msgResponse = new MsgResponse();
String errmsg = "ok";
int result = -1;
JSONObject jsonContent =new JSONObject();
if(userlist!=null){
jsonContent.put("user_mute_list", JSONArray.toJSONString(userlist));
String url = conversation_setmute_url.replace("ACCESS_TOKEN", accessToken);
JSONObject jsonObject = HttpUtil.sendPost(url, jsonContent.toJSONString());
if(null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
if(jsonObject.containsKey("errmsg")){
errmsg = jsonObject.getString("errmsg");
}
result = errcode;
}
msgResponse.setErrcode(result);
msgResponse.setErrmsg(errmsg);
}
return msgResponse;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Link.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Link.java | package com.jeecg.qywx.api.conversation.vo;
public class Link {
private String title;
private String description;
private String url;
private String thumb_media_id;
public Link(String title, String description, String url, String thumb_media_id) {
this.title = title;
this.description = description;
this.url = url;
this.thumb_media_id = thumb_media_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getThumb_media_id() {
return thumb_media_id;
}
public void setThumb_media_id(String thumb_media_id) {
this.thumb_media_id = thumb_media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/BaseMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/BaseMessage.java | package com.jeecg.qywx.api.conversation.vo;
public abstract class BaseMessage {
/**接收人*/
protected Receiver receiver;
/**发送人*/
protected String sender;
/**消息类型*/
protected String msgtype;
public BaseMessage() {
// TODO Auto-generated constructor stub
}
public BaseMessage(Receiver receiver, String sender, String msgtype) {
this.receiver = receiver;
this.sender = sender;
this.msgtype = msgtype;
}
public Receiver getReceiver() {
return receiver;
}
public void setReceiver(Receiver receiver) {
this.receiver = receiver;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Conversation.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Conversation.java | package com.jeecg.qywx.api.conversation.vo;
public class Conversation {
private String chatid;
private String name;
private String owner;
private String[] userlist;
public Conversation() {
// TODO Auto-generated constructor stub
}
public Conversation(String chatid, String name, String owner, String[] userlist) {
this.chatid = chatid;
this.name = name;
this.owner = owner;
this.userlist = userlist;
}
public String getChatid() {
return chatid;
}
public void setChatid(String chatid) {
this.chatid = chatid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String[] getUserlist() {
return userlist;
}
public void setUserlist(String[] userlist) {
this.userlist = userlist;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Conversation4Update.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Conversation4Update.java | package com.jeecg.qywx.api.conversation.vo;
public class Conversation4Update {
String chatid;
String op_user;
String name;
String owner;
String[] addUserlist;
String[] delUserlist;
public Conversation4Update() {
// TODO Auto-generated constructor stub
}
public Conversation4Update(String chatid, String op_user, String name, String owner, String[] addUserlist,
String[] delUserlist) {
this.chatid = chatid;
this.op_user = op_user;
this.name = name;
this.owner = owner;
this.addUserlist = addUserlist;
this.delUserlist = delUserlist;
}
public String getChatid() {
return chatid;
}
public void setChatid(String chatid) {
this.chatid = chatid;
}
public String getOp_user() {
return op_user;
}
public void setOp_user(String op_user) {
this.op_user = op_user;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String[] getAddUserlist() {
return addUserlist;
}
public void setAddUserlist(String[] addUserlist) {
this.addUserlist = addUserlist;
}
public String[] getDelUserlist() {
return delUserlist;
}
public void setDelUserlist(String[] delUserlist) {
this.delUserlist = delUserlist;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/LinkMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/LinkMessage.java | package com.jeecg.qywx.api.conversation.vo;
public class LinkMessage extends BaseMessage{
private Link link;
public LinkMessage() {
// TODO Auto-generated constructor stub
}
public LinkMessage(Receiver receiver, String sender,Link link) {
super(receiver, sender, "link");
this.link= link;
}
public Link getLink() {
return link;
}
public void setLink(Link link) {
this.link = link;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Media.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Media.java | package com.jeecg.qywx.api.conversation.vo;
public class Media {
private String media_id;
public Media() {
// TODO Auto-generated constructor stub
}
public Media(String media_id) {
this.media_id = media_id;
}
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/ImageMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/ImageMessage.java | package com.jeecg.qywx.api.conversation.vo;
/**
* 图片消息
* @author SunHaiFeng
*
*/
public class ImageMessage extends BaseMessage{
private Media image;
public ImageMessage() {
super.msgtype = "image";
}
public ImageMessage(Receiver receiver, String sender, Media image) {
super(receiver, sender, "image");
this.image = image;
}
public Media getImage() {
return image;
}
public void setImage(Media image) {
this.image = image;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/TextMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/TextMessage.java | package com.jeecg.qywx.api.conversation.vo;
/**
* 会话文本消息视图
* @author SunHaiFeng
*
*/
public class TextMessage extends BaseMessage{
/**文本内容*/
private Text text;
public TextMessage() {
super.msgtype = "text";
}
public TextMessage(Receiver receiver, String sender,Text text) {
super(receiver, sender, "text");
this.text = text;
}
public Receiver getReceiver() {
return receiver;
}
public void setReceiver(Receiver receiver) {
this.receiver = receiver;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public Text getText() {
return text;
}
public void setText(Text text) {
this.text = text;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/FileMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/FileMessage.java | package com.jeecg.qywx.api.conversation.vo;
/**
* 文件消息
* @author SunHaiFeng
*
*/
public class FileMessage extends BaseMessage{
private Media file;
public FileMessage() {
super.msgtype = "file";
}
public FileMessage(Receiver receiver, String sender,Media file) {
super(receiver, sender, "file");
this.file = file;
}
public Media getFile() {
return file;
}
public void setFile(Media file) {
this.file = file;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/VoiceMessage.java | src/main/java/com/jeecg/qywx/api/conversation/vo/VoiceMessage.java | package com.jeecg.qywx.api.conversation.vo;
public class VoiceMessage extends BaseMessage{
private Media voice;
public VoiceMessage() {
// TODO Auto-generated constructor stub
}
public VoiceMessage(Receiver receiver, String sender,Media voice) {
super(receiver, sender, "voice");
this.voice= voice;
}
public Media getVoice() {
return voice;
}
public void setVoice(Media voice) {
this.voice = voice;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Text.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Text.java | package com.jeecg.qywx.api.conversation.vo;
public class Text {
private String content;
public Text() {
// TODO Auto-generated constructor stub
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Receiver.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Receiver.java | package com.jeecg.qywx.api.conversation.vo;
public class Receiver {
private String type;
private String id;
public Receiver() {
// TODO Auto-generated constructor stub
}
public Receiver(String type, String id) {
this.type = type;
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/conversation/vo/Mute.java | src/main/java/com/jeecg/qywx/api/conversation/vo/Mute.java | package com.jeecg.qywx.api.conversation.vo;
public class Mute {
private String userid;
private Integer status;
public Mute(String userid, Integer status) {
this.userid = userid;
this.status = status;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/JwMessageAPI.java | src/main/java/com/jeecg/qywx/api/message/JwMessageAPI.java | package com.jeecg.qywx.api.message;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.message.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JwMessageAPI {
private static final Logger logger = LoggerFactory.getLogger(JwMessageAPI.class);
//发送消息(post)
static String message_send_url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
/*
* 发送文本信息
*/
public static JSONObject sendTextMessage(Text text, String accessToken) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},text:{}", new Object[]{accessToken,text});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken);
// 将信息对象转换成json字符串
String jsonText = JSONObject.toJSONString(text);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonText});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url,jsonText);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return jsonObject;
}
/*发送图片信息
*
*/
public static int sendImageMessage(Image image, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},image:{}", new Object[]{accessToken,agentid,image});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonImage = JSONObject.toJSONString(image);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonImage});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonImage);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*发送音频信息
*
*/
public static int sendVoiceMessage(Voice voice, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},voice:{}", new Object[]{accessToken,agentid,voice});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonVoice = JSONObject.toJSONString(voice);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonVoice});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonVoice);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 发送视频消息
*/
public static int sendVideoMessage(Video video, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},video:{}", new Object[]{accessToken,agentid,video});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonVideo = JSONObject.toJSONString(video);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonVideo});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonVideo);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 发送媒体文件
*
*/
public static int sendFileMessage(File file, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},file:{}", new Object[]{accessToken,agentid,file});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonFile = JSONObject.toJSONString(file);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonFile});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonFile);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 发送媒体文件消息
*
*/
public static JSONObject sendNewsMessage(News news, String accessToken) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},news:{}", new Object[]{accessToken,news});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken);
// 将信息对象转换成json字符串
String jsonNews = JSONObject.toJSONString(news);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonNews});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonNews);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return jsonObject;
}
/*
* 发送时直接带上素材
*
*/
public static int sendMpnewsMessage(Mpnews mpnews, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},mpnews:{}", new Object[]{accessToken,agentid,mpnews});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonMpnews = JSONObject.toJSONString(mpnews);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonMpnews});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonMpnews);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 发送时使用永久性图文素材
*
*/
public static int sendFixMpnewsMessage(FixMpnews fixmpnews, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},fixmpnews:{}", new Object[]{accessToken,agentid,fixmpnews});
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonFixMpnews = JSONObject.toJSONString(fixmpnews);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonFixMpnews});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonFixMpnews);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/**
* 发送文本卡片消息
*/
public static JSONObject sendTextCardMessage(TextCard textCard, String accessToken) {
logger.info("[JwMessage] sendTextCardMessage params:accessToken:{},textCard:{}", new Object[]{accessToken, textCard});
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken);
// 将信息对象转换成json字符串
String params = JSONObject.toJSONString(textCard);
logger.info("[JwMessage] sendTextCardMessage params:jsonText:{}", new Object[]{params});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, params);
logger.info("[JwMessage] sendTextCardMessage response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
}
/**
* 发送Markdown消息
*
* @param markdown 发送的Markdown消息
* @param accessToken 获取的access_token
*/
public static JSONObject sendMarkdownMessage(Markdown markdown, String accessToken) {
logger.info("[JwMessage] createText param:accessToken:{}, markdown:{}", accessToken, markdown);
int result = 0;
// 拼装发送信息的url
String url = message_send_url.replace("ACCESS_TOKEN", accessToken);
// 将信息对象转换成json字符串
String jsonText = JSON.toJSONString(markdown);
logger.info("[JwMessage] sendMessage param:jsonText:{}", jsonText);
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonText);
logger.info("[JwMessage] sendMessage response:{}", jsonObject.toJSONString());
return jsonObject;
}
//测试
public static void main(String[] args){
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
Text text=new Text();
text.setTouser("malimei");
// text.setToparty("678910");
// text.setTotag("112233");
text.setMsgtype("text");
text.setAgentid(1);
TextEntity text1=new TextEntity();
text1.setContent("aaaaaaa");
text.setText(text1);
text.setSafe("0");
JwMessageAPI.sendTextMessage(text, accessToken.getAccesstoken());
/*
* 图片
*/
/* Image image=new Image();
image.setTouser("malimei");
image.setMsgtype("image");
image.setAgentid(1);
ImageEntity imageEntity=new ImageEntity();
imageEntity.setMedia_id("1cjeJstIy7hU0FPsIEnXAj4QgTZZLVqI0Tjqamd8LzAUuGO6hMREqw-fUgiE2mpgD9Vw8qTWoIyhKa4-KF7PbBQ");
image.setImage(imageEntity);
String agentid="1";
JwMessageAPI.sendImageMessage(image, accessToken.getAccesstoken(), agentid);//{"errcode":0,"errmsg":"ok"}
*/
//1NSJSg-ccFTPqSG5ccqwTiIwsrGOY6-6nJ9SPyYl9pIOyEzH5kaAmHFll0_SU5R_6CVVCFLJsjC-_rpWr_jCXAg
/* Voice voice=new Voice();
voice.setTouser("malimei");
voice.setMsgtype("voice");
voice.setAgentid(1);
VoiceEntity voiceEntity=new VoiceEntity();
voiceEntity.setMedia_id("1NSJSg-ccFTPqSG5ccqwTiIwsrGOY6-6nJ9SPyYl9pIOyEzH5kaAmHFll0_SU5R_6CVVCFLJsjC-_rpWr_jCXAg");
voice.setVoice(voiceEntity);
String agentid="1";
JwMessageAPI.sendVoiceMessage(voice, accessToken.getAccesstoken(), agentid);//String agentid="1";
*/
/*
*视频
*
Video video=new Video();
video.setTouser("malimei");
video.setMsgtype("video");
video.setAgentid(1);
VideoEntity videoEntity=new VideoEntity();
videoEntity.setMedia_id("1k7eovYCr58zU4JC9CuDfvk3F1mL7EUqphvVMfNgBGw4D2_as1L5Nd9kRnK6hXv7TVIMl2u3uNlCvEQzgFW-iWw");
video.setVideo(videoEntity);
String agentid="1";
JwMessageAPI.sendVideoMessage(video, accessToken.getAccesstoken(), agentid);//{"errcode":0,"errmsg":"ok"}
**/
/*
* 文件
File file=new File();
file.setTouser("malimei");
file.setMsgtype("file");
file.setAgentid(1);
FileEntity fileEntity=new FileEntity();
fileEntity.setMedia_id("1k7eovYCr58zU4JC9CuDfvk3F1mL7EUqphvVMfNgBGw4D2_as1L5Nd9kRnK6hXv7TVIMl2u3uNlCvEQzgFW-iWw");
file.setFile(fileEntity);
String agentid="1";
JwMessageAPI.sendFileMessage(file, accessToken.getAccesstoken(), agentid);*/
/*发送图文信息
*
*/
News news=new News();
// news.setTouser("malimei|xinglei|zhoujf");
news.setToparty("1");
news.setMsgtype("news");
news.setAgentid(1);
NewsArticle newsArticles=new NewsArticle();
newsArticles.setTitle("哈喽");
String picurl="https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=eJ5FMzxYTeH12awmT33DAVUpPM2_zec8Nmct4N6rSMzE3f9L5ahksQ8dxqE0wjJE&media_id=1gbGp35rCKh_CT-Zl-d6HJeLubqyHqHiMevE56o2X6Ba2pxOp9wm-WMcOKwA5vbHezQrV_AiApj2V09KhzCV9yA";
newsArticles.setPicurl(picurl);
// NewsEntity newsEntity=new NewsEntity();
// newsEntity.setArticles(new NewsArticle[] {newsArticles});
// news.setNews(newsEntity);
NewsArticle newsArticles1=new NewsArticle();
newsArticles1.setTitle("你好");
String picurl1="https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=eJ5FMzxYTeH12awmT33DAVUpPM2_zec8Nmct4N6rSMzE3f9L5ahksQ8dxqE0wjJE&media_id=1gbGp35rCKh_CT-Zl-d6HJeLubqyHqHiMevE56o2X6Ba2pxOp9wm-WMcOKwA5vbHezQrV_AiApj2V09KhzCV9yA";
newsArticles.setPicurl(picurl1);
NewsEntity newsEntity1=new NewsEntity();
newsEntity1.setArticles(new NewsArticle[] {newsArticles1 ,newsArticles});
news.setNews(newsEntity1);
JwMessageAPI.sendNewsMessage(news, accessToken.getAccesstoken());
/*
*mpnews消息
*/
/* Mpnews mpnewsa=new Mpnews();
mpnewsa.setTouser("malimei");
mpnewsa.setMsgtype("mpnews");
mpnewsa.setAgentid(1);
MpnewsArticles articles=new MpnewsArticles();
articles.setTitle("嘿嘿");
articles.setContent("a");
articles.setThumb_media_id("1S9IBhHEbQ8eUpntYiTQioj6ttEi0Cbpve-2SRVcUEDo8-yKzGCD7JtSLpF7Qv5jgmt1SAmj2haczUx-rFa6Z0Q");
MpnewEntity mpnews=new MpnewEntity();
mpnews.setArticles(new MpnewsArticles[] {articles});
mpnews.setMpnews(mpnews);
String agentid="1";
//String accessToken="eJ5FMzxYTeH12awmT33DAVUpPM2_zec8Nmct4N6rSMzE3f9L5ahksQ8dxqE0wjJE";
JwMessageAPI.sendMpnewsMessage(mpnewsa, accessToken.getAccesstoken(), agentid);
*/
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/MpnewsEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/MpnewsEntity.java | package com.jeecg.qywx.api.message.vo;
public class MpnewsEntity {
private MpnewsArticles[] articles;//图文消息,一个图文消息支持1到8个图文
public MpnewsArticles[] getArticles() {
return articles;
}
public void setArticles(MpnewsArticles[] articles) {
this.articles = articles;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/MarkdownEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/MarkdownEntity.java | package com.jeecg.qywx.api.message.vo;
/**
* Markdown消息体
*
* @author sunjianlei
*/
public class MarkdownEntity {
/**
* 消息内容,最长不超过2048个字节,注意:主页型应用推送的文本消息在微信端最多只显示20个字(包含中英文)
*/
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/ImageEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/ImageEntity.java | package com.jeecg.qywx.api.message.vo;
public class ImageEntity {
private String media_id;//图片媒体文件id,可以调用上传临时素材或者永久素材接口获取,永久素材media_id必须由发消息的应用创建
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Mpnews.java | src/main/java/com/jeecg/qywx/api/message/vo/Mpnews.java | package com.jeecg.qywx.api.message.vo;
public class Mpnews {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private MpnewsEntity mpnews;//图文实体(发送时直接带上mpnews内容)
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public MpnewsEntity getMpnews() {
return mpnews;
}
public void setMpnews(MpnewsEntity mpnews) {
this.mpnews = mpnews;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/FixMpnewsEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/FixMpnewsEntity.java | package com.jeecg.qywx.api.message.vo;
public class FixMpnewsEntity {
private String media_id;
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Voice.java | src/main/java/com/jeecg/qywx/api/message/vo/Voice.java | package com.jeecg.qywx.api.message.vo;
public class Voice {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private VoiceEntity voice;//音频实体
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public VoiceEntity getVoice() {
return voice;
}
public void setVoice(VoiceEntity voice) {
this.voice = voice;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/TextEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/TextEntity.java | package com.jeecg.qywx.api.message.vo;
public class TextEntity {
private String content;//消息内容,最长不超过2048个字节,注意:主页型应用推送的文本消息在微信端最多只显示20个字(包含中英文)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/FileEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/FileEntity.java | package com.jeecg.qywx.api.message.vo;
public class FileEntity {
private String media_id;//媒体文件id,可以调用上传临时素材或者永久素材接口获取
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/VideoEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/VideoEntity.java | package com.jeecg.qywx.api.message.vo;
public class VideoEntity {
private String media_id;//视频媒体文件id,可以调用上传临时素材或者永久素材接口获取
private String title;//视频消息的标题,不超过128个字节,超过会自动截断
private String description;//视频消息的描述,不超过512个字节,超过会自动截断
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/News.java | src/main/java/com/jeecg/qywx/api/message/vo/News.java | package com.jeecg.qywx.api.message.vo;
public class News {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private NewsEntity news;//信息实体
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public NewsEntity getNews() {
return news;
}
public void setNews(NewsEntity news) {
this.news = news;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/VoiceEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/VoiceEntity.java | package com.jeecg.qywx.api.message.vo;
public class VoiceEntity {
private String media_id;//语音文件id,可以调用上传临时素材或者永久素材接口获取
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Image.java | src/main/java/com/jeecg/qywx/api/message/vo/Image.java | package com.jeecg.qywx.api.message.vo;
public class Image {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:image(不支持主页型应用)
private int agentid;// 企业应用的id,整型。可在应用的设置页面查看
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public void setAgentid(int agentid) {
this.agentid = agentid;
}
private ImageEntity image;// 图片媒体文件实体
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public ImageEntity getImage() {
return image;
}
public void setImage(ImageEntity image) {
this.image = image;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/MpnewsArticles.java | src/main/java/com/jeecg/qywx/api/message/vo/MpnewsArticles.java | package com.jeecg.qywx.api.message.vo;
public class MpnewsArticles {
private String title;//图文消息的标题,不超过128个字节,超过会自动截断
private String thumb_media_id;//图文消息缩略图的media_id, 可以在上传多媒体文件接口中获得。此处thumb_media_id即上传接口返回的media_id
private String author;//图文消息的作者,不超过64个字节
private String content_source_url;//图文消息点击“阅读原文”之后的页面链接
private String content;//图文消息的内容,支持html标签,不超过666 K个字节
private String digest;// 图文消息的描述,不超过512个字节,超过会自动截断
private String show_cover_pic;// 是否显示封面,1为显示,0为不显示
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumb_media_id() {
return thumb_media_id;
}
public void setThumb_media_id(String thumb_media_id) {
this.thumb_media_id = thumb_media_id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent_source_url() {
return content_source_url;
}
public void setContent_source_url(String content_source_url) {
this.content_source_url = content_source_url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public String getShow_cover_pic() {
return show_cover_pic;
}
public void setShow_cover_pic(String show_cover_pic) {
this.show_cover_pic = show_cover_pic;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/TextCardEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/TextCardEntity.java | package com.jeecg.qywx.api.message.vo;
/**
* @author sunjianlei
*/
public class TextCardEntity {
private String title; // 是 标题,不超过128个字节,超过会自动截断(支持id转译)
private String description;// 是 描述,不超过512个字节,超过会自动截断(支持id转译)
private String url; // 是 点击后跳转的链接。最长2048字节,请确保包含了协议头(http/https)
private String btntxt;// 否 按钮文字。 默认为“详情”, 不超过4个文字,超过自动截断。
public String getTitle() {
return title;
}
public TextCardEntity setTitle(String title) {
this.title = title;
return this;
}
public String getDescription() {
return description;
}
public TextCardEntity setDescription(String description) {
this.description = description;
return this;
}
public String getUrl() {
return url;
}
public TextCardEntity setUrl(String url) {
this.url = url;
return this;
}
public String getBtntxt() {
return btntxt;
}
public TextCardEntity setBtntxt(String btntxt) {
this.btntxt = btntxt;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/NewsEntity.java | src/main/java/com/jeecg/qywx/api/message/vo/NewsEntity.java | package com.jeecg.qywx.api.message.vo;
public class NewsEntity {
private NewsArticle[] articles;// 定义数组图文消息,一个图文消息支持1到8条图文
public NewsArticle[] getArticles() {
return articles;
}
public void setArticles(NewsArticle[] articles) {
this.articles = articles;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/File.java | src/main/java/com/jeecg/qywx/api/message/vo/File.java | package com.jeecg.qywx.api.message.vo;
public class File {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private FileEntity file;// 媒体文件实体
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public FileEntity getFile() {
return file;
}
public void setFile(FileEntity file) {
this.file = file;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/TextCard.java | src/main/java/com/jeecg/qywx/api/message/vo/TextCard.java | package com.jeecg.qywx.api.message.vo;
/**
* 企业微信文本卡片消息
*
* @author sunjianlei
*/
public class TextCard {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private TextCardEntity textcard;//信息实体
private String enable_id_trans;// 否 表示是否开启id转译,0表示否,1表示是,默认0
private String enable_duplicate_check;// 否 表示是否开启重复消息检查,0表示否,1表示是,默认0
private String duplicate_check_interval;// 否 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
//消息类型,此时固定为:textcard
public String getMsgtype() {
return "textcard";
}
public String getTouser() {
return touser;
}
public TextCard setTouser(String touser) {
this.touser = touser;
return this;
}
public String getToparty() {
return toparty;
}
public TextCard setToparty(String toparty) {
this.toparty = toparty;
return this;
}
public String getTotag() {
return totag;
}
public TextCard setTotag(String totag) {
this.totag = totag;
return this;
}
public int getAgentid() {
return agentid;
}
public TextCard setAgentid(int agentid) {
this.agentid = agentid;
return this;
}
public TextCardEntity getTextcard() {
return textcard;
}
public TextCard setTextcard(TextCardEntity textcard) {
this.textcard = textcard;
return this;
}
public String getEnable_id_trans() {
return enable_id_trans;
}
public TextCard setEnable_id_trans(String enable_id_trans) {
this.enable_id_trans = enable_id_trans;
return this;
}
public String getEnable_duplicate_check() {
return enable_duplicate_check;
}
public TextCard setEnable_duplicate_check(String enable_duplicate_check) {
this.enable_duplicate_check = enable_duplicate_check;
return this;
}
public String getDuplicate_check_interval() {
return duplicate_check_interval;
}
public TextCard setDuplicate_check_interval(String duplicate_check_interval) {
this.duplicate_check_interval = duplicate_check_interval;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Video.java | src/main/java/com/jeecg/qywx/api/message/vo/Video.java | package com.jeecg.qywx.api.message.vo;
public class Video {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private VideoEntity video;//视频实体
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public VideoEntity getVideo() {
return video;
}
public void setVideo(VideoEntity video) {
this.video = video;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Text.java | src/main/java/com/jeecg/qywx/api/message/vo/Text.java | package com.jeecg.qywx.api.message.vo;
public class Text {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
private String totag;//标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:text (支持消息型应用跟主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private TextEntity text;//消息内容实体
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public TextEntity getText() {
return text;
}
public void setText(TextEntity text) {
this.text = text;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/FixMpnews.java | src/main/java/com/jeecg/qywx/api/message/vo/FixMpnews.java | package com.jeecg.qywx.api.message.vo;
public class FixMpnews {
private String touser;//成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
private String toparty;//部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参
private String totag;// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
private String msgtype;//消息类型,此时固定为:voice (不支持主页型应用)
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private FixMpnewsEntity mpnews;//图文实体(发送时直接带上mpnews内容)
private String safe;// 表示是否是保密消息,0表示否,1表示是,默认0
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public FixMpnewsEntity getMpnews() {
return mpnews;
}
public void setMpnews(FixMpnewsEntity mpnews) {
this.mpnews = mpnews;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/Markdown.java | src/main/java/com/jeecg/qywx/api/message/vo/Markdown.java | package com.jeecg.qywx.api.message.vo;
/**
* Markdown消息
*
* @author sunjianlei
*/
public class Markdown {
public Markdown() {
this.msgtype = "markdown";
}
/**
* 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
*/
private String touser;
/**
* 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
*/
private String toparty;
/**
* 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
*/
private String totag;
/**
* 消息类型,此时固定为:text (支持消息型应用跟主页型应用)
*/
private String msgtype;
/**
* 企业应用的id,整型。可在应用的设置页面查看
*/
private int agentid;
/**
* 消息内容实体
*/
private MarkdownEntity markdown;
/**
* 表示是否是保密消息,0表示否,1表示是,默认0
*/
private String safe;
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getToparty() {
return toparty;
}
public void setToparty(String toparty) {
this.toparty = toparty;
}
public String getTotag() {
return totag;
}
public void setTotag(String totag) {
this.totag = totag;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public MarkdownEntity getMarkdown() {
return markdown;
}
public void setMarkdown(MarkdownEntity markdown) {
this.markdown = markdown;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/message/vo/NewsArticle.java | src/main/java/com/jeecg/qywx/api/message/vo/NewsArticle.java | package com.jeecg.qywx.api.message.vo;
public class NewsArticle {
private String title;//标题,不超过128个字节,超过会自动截断
private String description;//描述,不超过512个字节,超过会自动截断
private String url;//点击后跳转的链接。
private String picurl;//图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80。如不填,在客户端不显示图片
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getPicurl() {
return picurl;
}
public void setPicurl(String picurl) {
this.picurl = picurl;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/JwMediaAPI.java | src/main/java/com/jeecg/qywx/api/media/JwMediaAPI.java | package com.jeecg.qywx.api.media;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.core.util.WXUpload;
import com.jeecg.qywx.api.media.vo.FixSource;
import com.jeecg.qywx.api.media.vo.MpnewArticles;
import com.jeecg.qywx.api.media.vo.MpnewEntity;
import com.jeecg.qywx.api.media.vo.UpdateFixSource;
import com.jeecg.qywx.api.media.vo.UpdateFixSourceArticles;
import com.jeecg.qywx.api.media.vo.UpdateFixSourceEntity;
import com.jeecg.qywx.api.message.JwMessageAPI;
import com.jeecg.qywx.api.message.vo.FixMpnews;
import com.jeecg.qywx.api.message.vo.Image;
import com.jeecg.qywx.api.message.vo.Text;
public class JwMediaAPI {
private static final Logger logger = LoggerFactory.getLogger(JwMediaAPI.class);
//上传临时性图文素材
// public static String upload_source_url ="https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
//获取临时性图文素材
private static String sendsource_download_url="https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";
//上传永久性图文素材
private static String fixsource_upload_url="https://qyapi.weixin.qq.com/cgi-bin/material/add_mpnews?access_token=ACCESS_TOKEN";
//上传其他永久性素材
//private static String otherfixsource_upload_url="https://qyapi.weixin.qq.com/cgi-bin/material/add_material?agentid=AGENTID&type=TYPE&access_token=ACCESS_TOKEN";
//获取永久性素材
//private static String fixsource_download_url ="https://qyapi.weixin.qq.com/cgi-bin/material/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID&agentid=AGENTID";
//删除永久性素材
private static String FixSource_delete_url="https://qyapi.weixin.qq.com/cgi-bin/material/del?access_token=ACCESS_TOKEN&agentid=AGENTID&media_id=MEDIA_ID";
//修改永久图文素材
private static String fixsource_update_url ="https://qyapi.weixin.qq.com/cgi-bin/material/update_mpnews?access_token=ACCESS_TOKEN";
//获取素材总数
private static String source_count_url ="https://qyapi.weixin.qq.com/cgi-bin/material/get_count?access_token=ACCESS_TOKEN&agentid=AGENTID";
//获取素材列表
private static String source_list_url="https://qyapi.weixin.qq.com/cgi-bin/material/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID&agentid=AGENTID";
//上传图文信息内的图片
//private static String source_image_url="https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN";
/**
* 上传临时性素材
* @param fileType
* @param filePath
* @param token
* @return
* */
public static JSONObject sendMedia(String fileType,String filePath,String token) {
String result = null;
JSONObject jsonobject = new JSONObject();
jsonobject = null;
File file = new File(filePath);
if(!file.exists()||!file.isFile()){
jsonobject = null;
//org.jeecgframework.core.util.LogUtil.info("------------文件不存在------------------------");
}else{
try{
String requestUrl="https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token="+ token + "&type="+fileType;
//org.jeecgframework.core.util.LogUtil.info("------------------requestUr------------"+requestUrl);
URL urlObj = new URL(requestUrl);
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false); // post方式不能使用缓存
con.setRequestProperty("Connection", "Keep-Alive");// 设置请求头信息
con.setRequestProperty("Charset", "UTF-8");
String BOUNDARY = "----------" + System.currentTimeMillis();// 设置边界
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="+ BOUNDARY);
// 请求正文信息
// 第一部分:
StringBuilder sb = new StringBuilder();
sb.append("--"); // 必须多两道线
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data;name=\"file\";filename=\""+ file.getName() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
// 获得输出流
OutputStream out = new DataOutputStream(con.getOutputStream());
// 输出表头
out.write(head);
// 文件正文部分
// 把文件已流文件的方式 推入到url中
DataInputStream in = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
// 结尾部分
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
out.write(foot);
out.flush();
out.close();
StringBuffer buffer = new StringBuffer();
BufferedReader reader = null;
try {
// 定义BufferedReader输入流来读取URL的响应
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
if(result==null){
result = buffer.toString();
}
} catch (IOException e) {
// org.jeecgframework.core.util.LogUtil.info("发送POST请求出现异常!" + e);
e.printStackTrace();
throw new IOException("数据读取异常");
} finally {
if(reader!=null){
reader.close();
}
}
jsonobject = JSONObject.parseObject(result);
}catch(Exception e){
e.printStackTrace();
}
}
return jsonobject;
}
/*
*
* 获取临时素材文件
*
*/
/* public static JSONObject downloadsource(String accessToken,String media_id) {
logger.info("[GETMENU]", "getMenu param:accessToken:{},agentid:{}", new Object[]{accessToken,media_id});
// 拼装获取素材的url
String url =sendsource_download_url.replace("ACCESS_TOKEN", accessToken).replace("MEDIA_ID", media_id);
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
}
*/
/*
*
* 上传永久性素材
*/
public static int uploadfixsource(FixSource fixSource, String accessToken) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},fixmpnews:{}", new Object[]{accessToken,fixSource});
int result = 0;
// 拼装发送信息的url
String url = fixsource_upload_url.replace("ACCESS_TOKEN", accessToken) ;
// 将信息对象转换成json字符串
String jsonFixMpnews = JSONObject.toJSONString(fixSource);
logger.info("[CREATEMENU]", "sendMessage param:jsonText:{}", new Object[]{jsonFixMpnews});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonFixMpnews);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 上传其他永久性素材
*
*/
public static JSONObject sendotherMedia(String fileType,String filePath,String token,String agentid ) {
String result = null;
JSONObject jsonobject = new JSONObject();
jsonobject = null;
File file = new File(filePath);
if(!file.exists()||!file.isFile()){
jsonobject = null;
//org.jeecgframework.core.util.LogUtil.info("------------文件不存在------------------------");
}else{
try{
String requestUrl="https://qyapi.weixin.qq.com/cgi-bin/material/add_material?agentid="+agentid+"&access_token="+ token + "&type="+fileType;
//org.jeecgframework.core.util.LogUtil.info("------------------requestUr------------"+requestUrl);
URL urlObj = new URL(requestUrl);
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false); // post方式不能使用缓存
con.setRequestProperty("Connection", "Keep-Alive");// 设置请求头信息
con.setRequestProperty("Charset", "UTF-8");
String BOUNDARY = "----------" + System.currentTimeMillis();// 设置边界
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="+ BOUNDARY);
// 请求正文信息
// 第一部分:
StringBuilder sb = new StringBuilder();
sb.append("--"); // 必须多两道线
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data;name=\"file\";filename=\""+ file.getName() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
// 获得输出流
OutputStream out = new DataOutputStream(con.getOutputStream());
// 输出表头
out.write(head);
// 文件正文部分
// 把文件已流文件的方式 推入到url中
DataInputStream in = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
// 结尾部分
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
out.write(foot);
out.flush();
out.close();
StringBuffer buffer = new StringBuffer();
BufferedReader reader = null;
try {
// 定义BufferedReader输入流来读取URL的响应
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
if(result==null){
result = buffer.toString();
}
} catch (IOException e) {
// org.jeecgframework.core.util.LogUtil.info("发送POST请求出现异常!" + e);
e.printStackTrace();
throw new IOException("数据读取异常");
} finally {
if(reader!=null){
reader.close();
}
}
jsonobject = JSONObject.parseObject(result);
}catch(Exception e){
e.printStackTrace();
}
}
return jsonobject;
}
/*
* 获取永久素材
*
*/
/* public static JSONObject downloadFixsource(String accessToken,String agentid,String media_id ) {
logger.info("[GETMENU]", "getMenu param:accessToken:{},agentid:{}", new Object[]{accessToken,agentid});
int result = 0;
// 拼装获取素材的url
String url = fixsource_download_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid).replace("MEDIA_ID", media_id);
// 调用接口获取素材
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[CREATEMENU]", "sendMessage response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
} */
/*
* 删除永久性素材
*
*/
public static int deletefixSource(String accessToken,String agentid,String media_id) {
logger.info("[DELETEMENU]", "deletefixSource param:accessToken:{},agentid:{}", new Object[]{accessToken,agentid});
int result = 0;
// 拼装删除素材的url
String url = FixSource_delete_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid).replace("MEDIA_ID", media_id);
// 调用接口删除素材
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[DELETEMENU]", "deletefixSource response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/*
* 修改永久图文素材
*
*/
/* public static int updateSource(UpdateFixSource updateFixSource, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},image:{}", new Object[]{accessToken,agentid,updateFixSource});
int result = 0;
// 拼装发送信息的url
String url = fixsource_update_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将信息对象转换成json字符串
String jsonUpdateSource = JSONObject.toJSONString(updateFixSource);
logger.info("[CREATEMENU]", "jsonUpdateSource param:jsonText:{}", new Object[]{jsonUpdateSource});
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendPost(url, jsonUpdateSource);
logger.info("[CREATEMENU]", "jsonUpdateSource response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
} */
/*
* 获取素材总数
*/
public static JSONObject getCountSource( String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},image:{}", new Object[]{accessToken,agentid});
int result = 0;
// 拼装发送信息的url
String url = fixsource_update_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[CREATEMENU]", "jsonUpdateSource response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
}
/*
* 获取素材列表
*
*
*/
/* public static JSONObject getlistSource( String accessToken,String agentid,String media_id) {
logger.info("[CREATEMENU]", "createText param:accessToken:{},agentid:{},image:{}", new Object[]{accessToken,agentid});
int result = 0;
// 拼装发送信息的url
String url = fixsource_update_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid).replace("MEDIA_ID", media_id);
// 调用接口发送信息
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[CREATEMENU]", "jsonUpdateSource response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
} */
/*
*
* 上传图文消息内的图片
*
*/
public static JSONObject sendImageMedia(String fileType,String filePath,String token) {
String result = null;
JSONObject jsonobject = new JSONObject();
jsonobject = null;
File file = new File(filePath);
if(!file.exists()||!file.isFile()){
jsonobject = null;
//org.jeecgframework.core.util.LogUtil.info("------------文件不存在------------------------");
}else{
try{
String requestUrl="https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token="+ token;
//org.jeecgframework.core.util.LogUtil.info("------------------requestUr------------"+requestUrl);
URL urlObj = new URL(requestUrl);
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false); // post方式不能使用缓存
con.setRequestProperty("Connection", "Keep-Alive");// 设置请求头信息
con.setRequestProperty("Charset", "UTF-8");
String BOUNDARY = "----------" + System.currentTimeMillis();// 设置边界
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="+ BOUNDARY);
// 请求正文信息
// 第一部分:
StringBuilder sb = new StringBuilder();
sb.append("--"); // 必须多两道线
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data;name=\"file\";filename=\""+ file.getName() + "\"\r\n");
sb.append("Content-Type:application/octet-stream\r\n\r\n");
byte[] head = sb.toString().getBytes("utf-8");
// 获得输出流
OutputStream out = new DataOutputStream(con.getOutputStream());
// 输出表头
out.write(head);
// 文件正文部分
// 把文件已流文件的方式 推入到url中
DataInputStream in = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
// 结尾部分
byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
out.write(foot);
out.flush();
out.close();
StringBuffer buffer = new StringBuffer();
BufferedReader reader = null;
try {
// 定义BufferedReader输入流来读取URL的响应
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
if(result==null){
result = buffer.toString();
}
} catch (IOException e) {
// org.jeecgframework.core.util.LogUtil.info("发送POST请求出现异常!" + e);
e.printStackTrace();
throw new IOException("数据读取异常");
} finally {
if(reader!=null){
reader.close();
}
}
jsonobject = JSONObject.parseObject(result);
}catch(Exception e){
e.printStackTrace();
}
}
return jsonobject;
}
public static void main(String[] args) {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);//获取token
/*上传临时性
*
*/
String fileType="image";
String filePath="F:\\upload\\img\\cashprizes\\gh_f268aa85d1c7\\oDltNwWtFEEcFOc7XvnG2YzPglBQ_bm.jpg";
JwMediaAPI.sendMedia(fileType,filePath, accessToken.getAccesstoken());//测试结果{"created_at":1462426106,"media_id":"1cjeJstIy7hU0FPsIEnXAj4QgTZZLVqI0Tjqamd8LzAUuGO6hMREqw-fUgiE2mpgD9Vw8qTWoIyhKa4-KF7PbBQ","type":"image"}
/*获取临时性
*
String media_id="1gbGp35rCKh_CT-Zl-d6HJeLubqyHqHiMevE56o2X6Ba2pxOp9wm-WMcOKwA5vbHezQrV_AiApj2V09KhzCV9yA";
String accessToken="eJ5FMzxYTeH12awmT33DAVUpPM2_zec8Nmct4N6rSMzE3f9L5ahksQ8dxqE0wjJE";
JwMediaAPI.downloadsource(accessToken,media_id);*/
/*
* 上传永久性
FixSource fixSource=new FixSource();
fixSource.setAgentid(1);
MpnewEntity mpnews=new MpnewEntity();
MpnewArticles mpnewArticles=new MpnewArticles();
mpnewArticles.setTitle("aaa");
mpnewArticles.setThumb_media_id("1E2g4VgQjVCSTdVdM8f8B1JRcpk2YPJpjwlOohgMN0TE5MY69gyb-Er7LXlQUGRg9cyGm58cCHw1sn-e15590-g");
mpnewArticles.setAuthor("张三");
mpnewArticles.setContent("张三吃西瓜");
mpnews.setArticles(new MpnewArticles[] {mpnewArticles});
fixSource.setMpnews(mpnews);
JwMediaAPI.uploadfixsource(fixSource, accessToken.getAccesstoken());//测试结果{"errcode":0,"errmsg":"ok","media_id":"2VJ7_-3M4R-hzDcCXP-LJjebxkbxh0ufqGcS19LSH8yGXh_mJHob2bV8KKZ-sZ5Nu"}
//第二次:token:2PmTUAutNqjcO7PB75dVT4ozFsr3J33qbV6xp8SF3hqnyiSXC4DLnW26WVrrkImI {"errcode":0,"errmsg":"ok","media_id":"2VJ7_-3M4R-hzDcCXP-LJjRZbfAfIMYlgz16vzqbLIJCQZNQAilAS7K1t30d2UX4v"}
*/
/*上传其他永久性素材
*
String fileType="image";
String filePath="F:\\upload\\img\\cashprizes\\gh_f268aa85d1c7\\oDltNwWtFEEcFOc7XvnG2YzPglBQ_bm.jpg";
String agentid="1";//token qZxor_y_ux21TiGIwqQbUrDlNfSoXBLSkO3oCmaCPoqhEuI2XYd_ZfUbYPCltqd8
JwMediaAPI.sendotherMedia(fileType, filePath, accessToken.getAccesstoken(), agentid);//测试结果{"errcode":0,"errmsg":"ok","media_id":"2RWVnjuNYmfG1e5azwyIlCZ0FK1nZmkF52MqkAsAp_eGvZ7vm_EFWBH_7fK0doAmtgL6dcNI843iB0Jqz3iHQvg"}
*/
/*删除永久性素材
*
String media_id="2RWVnjuNYmfG1e5azwyIlCZ0FK1nZmkF52MqkAsAp_eGvZ7vm_EFWBH_7fK0doAmtgL6dcNI843iB0Jqz3iHQvg";
String agentid="1";
String accessToken="qZxor_y_ux21TiGIwqQbUrDlNfSoXBLSkO3oCmaCPoqhEuI2XYd_ZfUbYPCltqd8";
JwMediaAPI.deletefixSource(accessToken, agentid, media_id);//测试结果{"errcode":0,"errmsg":"deleted"}
*/
/*
* 修改永久图文素材
*
UpdateFixSource updateFixSource=new UpdateFixSource();
updateFixSource.setAgentid(1);
updateFixSource.setMedia_id("2VJ7_-3M4R-hzDcCXP-LJjRZbfAfIMYlgz16vzqbLIJCQZNQAilAS7K1t30d2UX4v");
UpdateFixSourceArticles updateFixSourceArticles=new UpdateFixSourceArticles();
updateFixSourceArticles.setTitle("小马书籍");
updateFixSourceArticles.setThumb_media_id("1E2g4VgQjVCSTdVdM8f8B1JRcpk2YPJpjwlOohgMN0TE5MY69gyb-Er7LXlQUGRg9cyGm58cCHw1sn-e15590-g");
updateFixSourceArticles.setAuthor("小马");
updateFixSourceArticles.setContent("旅游宝典");
UpdateFixSourceEntity articles=new UpdateFixSourceEntity();
articles.setArticles(new UpdateFixSourceArticles[] {updateFixSourceArticles});
updateFixSource.setMpnews(articles);
String accessToken="2PmTUAutNqjcO7PB75dVT4ozFsr3J33qbV6xp8SF3hqnyiSXC4DLnW26WVrrkImI";
String agentid="1";
JwMediaAPI.updateSource(updateFixSource, accessToken, agentid);//测试结果 {"errcode":0,"errmsg":"ok"}
*/
/* 上传图文消息内的图片
* String fileType="image";
String filePath= "F:\\upload\\img\\cashprizes\\gh_f268aa85d1c7\\oDltNwWtFEEcFOc7XvnG2YzPglBQ_bm.jpg";
JwMediaAPI.sendImageMedia(fileType, filePath, accessToken.getAccesstoken());//{"url":"http://shp.qpic.cn/bizmp/UBykN6XtpLSxK2mNnOcvPD7YthhbqTMK8sttheZGm8KLlpk1LCgFiaQ/"}
*/
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSourceEntity.java | src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSourceEntity.java | package com.jeecg.qywx.api.media.vo;
public class UpdateFixSourceEntity {
private UpdateFixSourceArticles[] articles;// 图文消息,一个图文消息支持1到10个图文
public UpdateFixSourceArticles[] getArticles() {
return articles;
}
public void setArticles(UpdateFixSourceArticles[] articles) {
this.articles = articles;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSourceArticles.java | src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSourceArticles.java | package com.jeecg.qywx.api.media.vo;
public class UpdateFixSourceArticles {
private String title;//图文消息的标题
private String thumb_media_id;//图文消息缩略图的media_id, 可以在上传永久素材接口中获得
private String author;//图文消息的作者
private String content_source_url;// 图文消息点击“阅读原文”之后的页面链接
private String content;//图文消息的内容,支持html标签
private String digest;//图文消息的描述
private String show_cover_pic;//是否显示封面,1为显示,0为不显示。默认为0
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumb_media_id() {
return thumb_media_id;
}
public void setThumb_media_id(String thumb_media_id) {
this.thumb_media_id = thumb_media_id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent_source_url() {
return content_source_url;
}
public void setContent_source_url(String content_source_url) {
this.content_source_url = content_source_url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public String getShow_cover_pic() {
return show_cover_pic;
}
public void setShow_cover_pic(String show_cover_pic) {
this.show_cover_pic = show_cover_pic;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/FixSource.java | src/main/java/com/jeecg/qywx/api/media/vo/FixSource.java | package com.jeecg.qywx.api.media.vo;
public class FixSource {
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private MpnewEntity mpnews;
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public MpnewEntity getMpnews() {
return mpnews;
}
public void setMpnews(MpnewEntity mpnews) {
this.mpnews = mpnews;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/MpnewArticles.java | src/main/java/com/jeecg/qywx/api/media/vo/MpnewArticles.java | package com.jeecg.qywx.api.media.vo;
public class MpnewArticles {
private String title;//图文消息的标题
private String thumb_media_id;//图文消息缩略图的media_id, 可以在上传永久素材接口中获得
private String author;//图文消息的作者
private String content_source_url;// 图文消息点击“阅读原文”之后的页面链接
private String content;//图文消息的内容,支持html标签
private String digest;//图文消息的描述
private String show_cover_pic;//是否显示封面,1为显示,0为不显示。默认为0
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getThumb_media_id() {
return thumb_media_id;
}
public void setThumb_media_id(String thumb_media_id) {
this.thumb_media_id = thumb_media_id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent_source_url() {
return content_source_url;
}
public void setContent_source_url(String content_source_url) {
this.content_source_url = content_source_url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public String getShow_cover_pic() {
return show_cover_pic;
}
public void setShow_cover_pic(String show_cover_pic) {
this.show_cover_pic = show_cover_pic;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/MpnewEntity.java | src/main/java/com/jeecg/qywx/api/media/vo/MpnewEntity.java | package com.jeecg.qywx.api.media.vo;
import com.jeecg.qywx.api.message.vo.MpnewsArticles;
public class MpnewEntity {
private MpnewArticles[] articles;// 图文消息,一个图文消息支持1到10个图文
public MpnewArticles[] getArticles() {
return articles;
}
public void setArticles(MpnewArticles[] articles) {
this.articles = articles;
}
public void setArticles(MpnewsArticles[] mpnewsArticles) {
// TODO Auto-generated method stub
}
public void setMpnews(MpnewEntity mpnews) {
// TODO Auto-generated method stub
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSource.java | src/main/java/com/jeecg/qywx/api/media/vo/UpdateFixSource.java | package com.jeecg.qywx.api.media.vo;
public class UpdateFixSource {
private int agentid;//企业应用的id,整型。可在应用的设置页面查看
private String media_id;
private UpdateFixSourceEntity mpnews;
public int getAgentid() {
return agentid;
}
public void setAgentid(int agentid) {
this.agentid = agentid;
}
public String getMedia_id() {
return media_id;
}
public void setMedia_id(String media_id) {
this.media_id = media_id;
}
public UpdateFixSourceEntity getMpnews() {
return mpnews;
}
public void setMpnews(UpdateFixSourceEntity mpnews) {
this.mpnews = mpnews;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/core/util/HttpUtil.java | src/main/java/com/jeecg/qywx/api/core/util/HttpUtil.java | package com.jeecg.qywx.api.core.util;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
/**
* @author zhoujf
*
*/
public class HttpUtil {
private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
/**
* http get请求
* @param url
* @return
*/
public static JSONObject sendGet(String url) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"GET",null);
return jsonObject;
}
/**
* http post请求
* @param url
* @return
*/
public static JSONObject sendPost(String url) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"POST",null);
return jsonObject;
}
/**
* http post请求
* @param url
* @param output json串
* @return
*/
public static JSONObject sendPost(String url,String output) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"POST",output);
return jsonObject;
}
/**
* 发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
private static JSONObject httpRequest(String request , String requestMethod , String output){
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
try {
logger.debug("[HTTP]", "http请求request:{},method:{},output{}", new Object[]{request,requestMethod,output});
//建立连接
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(3000);
connection.setReadTimeout(30000);
connection.setUseCaches(false);
connection.setRequestMethod(requestMethod);
if(output!=null){
OutputStream out = connection.getOutputStream();
out.write(output.getBytes("UTF-8"));
out.close();
}
//流处理
inputStream = connection.getInputStream();
inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
reader = new BufferedReader(inputStreamReader);
String line;
while((line=reader.readLine())!=null){
buffer.append(line);
}
//关闭连接、释放资源
reader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
connection.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (Exception e) {
logger.error("[HTTP]", "http请求error:{}", new Object[]{e.getMessage()});
}finally {
// 使用finally块来关闭输出流、输入流
try {
if (reader != null) {
reader.close();
}
if(inputStreamReader!=null){
inputStreamReader.close();
}
if(inputStream!=null){
inputStream.close();
}
} catch (Exception ex) {
ex.printStackTrace();
logger.error("[HTTP]", "http请求error:{}", new Object[]{ex.getMessage()});
}
}
return jsonObject;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java | src/main/java/com/jeecg/qywx/api/core/util/WXUpload.java | package com.jeecg.qywx.api.core.util;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.internal.util.StringUtils;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class WXUpload {
private static final String upload_wechat_url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
/**
*
* @param accessToken
* @param type 有image 类型
* @param fileUrl 一定要注意 这个类型为全路径名称哦
* @return
*/
public static JSONObject upload(String accessToken, String type, String fileUrl) {
JSONObject jsonObject = null;
String last_wechat_url = upload_wechat_url.replace("ACCESS_TOKEN", accessToken).replace("TYPE", type);
// 定义数据分割符
String boundary = "----------sunlight";
try {
URL uploadUrl = new URL(last_wechat_url);
HttpURLConnection uploadConn = (HttpURLConnection) uploadUrl.openConnection();
uploadConn.setDoOutput(true);
uploadConn.setDoInput(true);
uploadConn.setRequestMethod("POST");
// 设置请求头Content-Type
uploadConn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
// 获取媒体文件上传的输出流(往微信服务器写数据)
OutputStream outputStream = uploadConn.getOutputStream();
URL mediaUrl = new URL(fileUrl);
HttpURLConnection meidaConn = (HttpURLConnection) mediaUrl.openConnection();
meidaConn.setDoOutput(true);
meidaConn.setRequestMethod("GET");
// 从请求头中获取内容类型
String contentType = meidaConn.getHeaderField("Content-Type");
String filename=getFileName(fileUrl,contentType);
// 请求体开始
outputStream.write(("--" + boundary + "\r\n").getBytes());
outputStream.write(String.format("Content-Disposition: form-data; name=\"media\"; filename=\"%s\"\r\n", filename).getBytes());
outputStream.write(String.format("Content-Type: %s\r\n\r\n", contentType).getBytes());
// 获取媒体文件的输入流(读取文件)
BufferedInputStream bis = new BufferedInputStream(meidaConn.getInputStream());
byte[] buf = new byte[1024 * 8];
int size = 0;
while ((size = bis.read(buf)) != -1) {
// 将媒体文件写到输出流(往微信服务器写数据)
outputStream.write(buf, 0, size);
}
// 请求体结束
outputStream.write(("\r\n--" + boundary + "--\r\n").getBytes());
outputStream.close();
bis.close();
meidaConn.disconnect();
// 获取媒体文件上传的输入流(从微信服务器读数据)
InputStream inputStream = uploadConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer buffer = new StringBuffer();
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
uploadConn.disconnect();
// 使用json解析
// jsonObject = JSONObject.fromObject(buffer.toString());
jsonObject = JSONObject.parseObject(buffer.toString());
System.out.println("jsonobject="+jsonObject);
} catch (Exception e) {
System.out.println("上传文件失败!");
e.printStackTrace();
}
return jsonObject;
}
public static String getFileName(String fileUrl,String contentType) {
String filename="";
if (fileUrl != null && !"".equals(fileUrl)) {
if(fileUrl.contains(".")){
filename = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
}else{
if(contentType==null || "".equals(contentType)){
return "";
}
String fileExt="";
if ("image/jpeg".equals(contentType)) {
fileExt = ".jpg";
} else if ("audio/mpeg".equals(contentType)) {
fileExt = ".mp3";
} else if ("audio/amr".equals(contentType)) {
fileExt = ".amr";
} else if ("video/mp4".equals(contentType)) {
fileExt = ".mp4";
} else if ("video/mpeg4".equals(contentType)) {
fileExt = ".mp4";
} else if ("text/plain".equals(contentType)) {
fileExt = ".txt";
} else if ("text/xml".equals(contentType)) {
fileExt = ".xml";
} else if ("application/pdf".equals(contentType)) {
fileExt = ".pdf";
} else if ("application/msword".equals(contentType)) {
fileExt = ".doc";
} else if ("application/vnd.ms-powerpoint".equals(contentType)) {
fileExt = ".ppt";
} else if ("application/vnd.ms-excel".equals(contentType)) {
fileExt = ".xls";
}
filename="Media文件"+fileExt;
}
}
return filename;
}
/**
*
* @param data
* 要写入的数据
* @param dir
* 目录
* @param filename
* 文件名称
* @param cover
* 是否覆盖
* @throws IOException
* 文件流错误
* @throws Exception
* 自定义异常
*/
public static void writeFile(byte[] data, String dir, String filename,
boolean cover) {
try {
if (StringUtils.isEmpty(dir)) {
throw new Exception("目录不能为空");
}
if (StringUtils.isEmpty(filename)) {
throw new Exception("文件名称不能为空");
}
File dirfile = new File(dir);
if (dirfile.isFile()) {
throw new Exception("目录不能是文件");
}
if (!dirfile.exists()) {
// 创建目录
dirfile.mkdirs();
}
File file = new File(dir + "//" + filename);
if (file.exists()) {
if (cover) {
file.setWritable(true);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
new FileOutputStream(file));
bufferedOutputStream.write(data);
bufferedOutputStream.close();
} else {
return;
}
} else {
file.setWritable(true);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
new FileOutputStream(file));
bufferedOutputStream.write(data);
bufferedOutputStream.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
// JSONObject object = WXUpload.upload(accessToken.getAccesstoken(), "image", "file:///D:/shjjj.jpg");
JSONObject object = WXUpload.upload(accessToken.getAccesstoken(), "image", "http://127.0.0.1:80/jeecg-p3-web/upload/shjjj.jpg");
System.out.println(object.toString());
/*try {
URL mediaUrl = new URL("file://D:/shjjj.jpg");
System.out.println( mediaUrl.openConnection());
HttpURLConnection meidaConn = (HttpURLConnection) mediaUrl.openConnection();
meidaConn.setDoOutput(true);
meidaConn.setRequestMethod("GET");
// System.out.println(fileUrl.openConnection());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
//jsonobject={"created_at":1461249116,"media_id":"1Njk4eIayIxlo9NK7o17ze3GAu1nrOd4Xz9qXCSUQ0UWl59e2jf4-RAIpq_iZyhbXFAI98cN2blBS0ltMg9i0eg","type":"image"}
// {"created_at":1461249116,"media_id":"1Njk4eIayIxlo9NK7o17ze3GAu1nrOd4Xz9qXCSUQ0UWl59e2jf4-RAIpq_iZyhbXFAI98cN2blBS0ltMg9i0eg","type":"image"}
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/core/common/MsgResponse.java | src/main/java/com/jeecg/qywx/api/core/common/MsgResponse.java | package com.jeecg.qywx.api.core.common;
import java.io.Serializable;
/**
* 微信接口响应
*
* @author zhoujf
*/
public class MsgResponse implements Serializable {
private static final long serialVersionUID = 6102281663991601498L;
private Integer errcode;
private String errmsg;
public Integer getErrcode() {
return errcode;
}
public void setErrcode(Integer errcode) {
this.errcode = errcode;
}
public String getErrmsg() {
return errmsg;
}
public void setErrmsg(String errmsg) {
this.errmsg = errmsg;
}
@Override
public String toString() {
return "MsgResponse [errcode=" + errcode + ", errmsg=" + errmsg + "]";
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/core/common/AccessToken.java | src/main/java/com/jeecg/qywx/api/core/common/AccessToken.java | package com.jeecg.qywx.api.core.common;
/**
* 微信通用接口凭证
*
* @author zhoujf
* @date 2016-04-05
*/
public class AccessToken {
// 获取到的凭证
private String accesstoken;
// 凭证有效时间,单位:秒
private int expiresIn;
public String getAccesstoken() {
return accesstoken;
}
public void setAccesstoken(String accesstoken) {
this.accesstoken = accesstoken;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
public String toString() {
return "AccessToken [accesstoken=" + accesstoken + ", expiresIn="
+ expiresIn + "]";
}
} | java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/JwMenuAPI.java | src/main/java/com/jeecg/qywx/api/menu/JwMenuAPI.java | package com.jeecg.qywx.api.menu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.qywx.api.base.JwAccessTokenAPI;
import com.jeecg.qywx.api.base.JwParamesAPI;
import com.jeecg.qywx.api.core.common.AccessToken;
import com.jeecg.qywx.api.core.util.HttpUtil;
import com.jeecg.qywx.api.menu.vo.Button;
import com.jeecg.qywx.api.menu.vo.CommonButton;
import com.jeecg.qywx.api.menu.vo.ComplexButton;
import com.jeecg.qywx.api.menu.vo.Menu;
import com.jeecg.qywx.api.menu.vo.ViewButton;
/**
* 企业微信--menu
*
* @author zhoujf
*
*/
public class JwMenuAPI {
private static final Logger logger = LoggerFactory.getLogger(JwMenuAPI.class);
//创建应用菜单(POST)
private static String menu_create_url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN&agentid=AGENTID";
//删除菜单(GET)
private static String menu_delete_url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN&agentid=AGENTID";
//获取菜单列表(GET)
private static String menu_get_url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN&agentid=AGENTID";
/**
* 创建应用菜单
* @param menu 菜单实例
* button 是 一级菜单数组,个数应为1~3个
* sub_button 否 二级菜单数组,个数应为1~5个
* type 是 菜单的响应动作类型
* name 是 菜单标题,不超过16个字节,子菜单不超过40个字节
* key click等点击类型必须 菜单KEY值,用于消息接口推送,不超过128字节
* url view类型必须 网页链接,用户点击菜单可打开链接,不超过256字节
* @param accessToken 有效的access_token
* @param agentid 企业应用的id,整型,可在应用的设置页面查看
* @return 0表示成功,其他值表示失败
*/
public static int createMenu(Menu menu, String accessToken,String agentid) {
logger.info("[CREATEMENU]", "createMenu param:accessToken:{},agentid:{},menu:{}", new Object[]{accessToken,agentid,menu});
int result = 0;
// 拼装创建菜单的url
String url = menu_create_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 将菜单对象转换成json字符串
String jsonMenu = JSONObject.toJSONString(menu);
logger.info("[CREATEMENU]", "createMenu param:jsonMenu:{}", new Object[]{jsonMenu});
// 调用接口创建菜单
JSONObject jsonObject = HttpUtil.sendPost(url, jsonMenu);
logger.info("[CREATEMENU]", "createMenu response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/**
* 删除菜单
* @param accessToken 有效的access_token
* @param agentid 企业应用的id,整型,可在应用的设置页面查看
* @return 0表示成功,其他值表示失败
*/
public static int deleteMenu(String accessToken,String agentid) {
logger.info("[DELETEMENU]", "deleteMenu param:accessToken:{},agentid:{}", new Object[]{accessToken,agentid});
int result = 0;
// 拼装删除菜单的url
String url = menu_delete_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 调用接口删除菜单
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[DELETEMENU]", "deleteMenu response:{}", new Object[]{jsonObject.toJSONString()});
if (null != jsonObject) {
int errcode = jsonObject.getIntValue("errcode");
result = errcode;
}
return result;
}
/**
* 获取菜单列表
* @param accessToken 有效的access_token
* @param agentid 企业应用的id,整型,可在应用的设置页面查看
* @return
*/
public static JSONObject getMenu(String accessToken,String agentid) {
logger.info("[GETMENU]", "getMenu param:accessToken:{},agentid:{}", new Object[]{accessToken,agentid});
// 拼装获取菜单列表的url
String url = menu_get_url.replace("ACCESS_TOKEN", accessToken).replace("AGENTID", agentid);
// 调用接口获取菜单列表
JSONObject jsonObject = HttpUtil.sendGet(url);
logger.info("[GETMENU]", "getMenu response:{}", new Object[]{jsonObject.toJSONString()});
return jsonObject;
}
public static void main(String[] args){
try {
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(JwParamesAPI.corpId,JwParamesAPI.secret);
Menu menu = new Menu();
CommonButton btn11 = new CommonButton();
btn11.setName("菜单1-1");
btn11.setType("click");
btn11.setKey("11");
CommonButton btn12 = new CommonButton();
btn12.setName("菜单1-2");
btn12.setType("click");
btn12.setKey("12");
CommonButton btn13 = new CommonButton();
btn13.setName("菜单1-3");
btn13.setType("click");
btn13.setKey("13");
CommonButton btn14 = new CommonButton();
btn14.setName("菜单1-4");
btn14.setType("click");
btn14.setKey("14");
CommonButton btn15 = new CommonButton();
btn15.setName("菜单1-5");
btn15.setType("click");
btn15.setKey("15");
CommonButton btn21 = new CommonButton();
btn21.setName("菜单2-1");
btn21.setType("click");
btn21.setKey("21");
CommonButton btn22 = new CommonButton();
btn22.setName("菜单2-2");
btn22.setType("click");
btn22.setKey("22");
CommonButton btn23 = new CommonButton();
btn23.setName("菜单2-3");
btn23.setType("click");
btn23.setKey("23");
CommonButton btn24 = new CommonButton();
btn24.setName("菜单2-4");
btn24.setType("click");
btn24.setKey("24");
CommonButton btn25 = new CommonButton();
btn25.setName("菜单2-5");
btn25.setType("click");
btn25.setKey("25");
ViewButton btn31 = new ViewButton();
btn31.setName("菜单Url3-1");
btn31.setType("view");
btn31.setUrl("http://www.baidu.com");
CommonButton btn32 = new CommonButton();
btn32.setName("菜单3-2");
btn32.setType("click");
btn32.setKey("32");
CommonButton btn33 = new CommonButton();
btn33.setName("菜单3-3");
btn33.setType("click");
btn33.setKey("33");
CommonButton btn34 = new CommonButton();
btn34.setName("菜单3-4");
btn34.setType("click");
btn34.setKey("34");
CommonButton btn35 = new CommonButton();
btn35.setName("菜单3-5");
btn35.setType("click");
btn35.setKey("35");
ComplexButton mainBtn1 = new ComplexButton();
mainBtn1.setName("菜单1");
mainBtn1.setSub_button(new Button[] { btn11, btn12, btn13, btn14, btn15});
ComplexButton mainBtn2 = new ComplexButton();
mainBtn2.setName("菜单2");
mainBtn2.setSub_button(new Button[] { btn21, btn22, btn23, btn24, btn25 });
ComplexButton mainBtn3 = new ComplexButton();
mainBtn3.setName("菜单3");
mainBtn3.setSub_button(new Button[] { btn31, btn32, btn33, btn34, btn35});
menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });
//创建菜单
JwMenuAPI.createMenu(menu, accessToken.getAccesstoken(), JwParamesAPI.agentid);
//删除菜单
// JwMenuAPI.deleteMenu(accessToken.getAccesstoken(), JwParamesAPI.agentid);
//获取菜单列表
// JwMenuAPI.getMenu(accessToken.getAccesstoken(), JwParamesAPI.agentid);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/vo/ComplexButton.java | src/main/java/com/jeecg/qywx/api/menu/vo/ComplexButton.java | package com.jeecg.qywx.api.menu.vo;
import java.util.Arrays;
/**
* 复杂按钮(父按钮)
*
* @author zhoujf
* @date 2016-04-05
*/
public class ComplexButton extends Button {
private Button[] sub_button;
public Button[] getSub_button() {
return sub_button;
}
public void setSub_button(Button[] sub_button) {
this.sub_button = sub_button;
}
@Override
public String toString() {
return "ComplexButton [sub_button=" + Arrays.toString(sub_button) + "]";
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/vo/Button.java | src/main/java/com/jeecg/qywx/api/menu/vo/Button.java | package com.jeecg.qywx.api.menu.vo;
/**
* 按钮的基类
*
* @author zhoujf
* @date 2016-04-05
*/
public class Button {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Button [name=" + name + "]";
}
} | java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/vo/ViewButton.java | src/main/java/com/jeecg/qywx/api/menu/vo/ViewButton.java | package com.jeecg.qywx.api.menu.vo;
/**
* view类型的菜单
*
* @author zhoujf
* @date 2016-04-05
*/
public class ViewButton extends Button {
private String type;
private String url;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "ViewButton [type=" + type + ", url=" + url + "]";
}
} | java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/vo/Menu.java | src/main/java/com/jeecg/qywx/api/menu/vo/Menu.java | package com.jeecg.qywx.api.menu.vo;
import java.util.Arrays;
/**
* 菜单
*
*@author zhoujf
*@date 2016-04-05
*/
public class Menu {
private Button[] button;
public Button[] getButton() {
return button;
}
public void setButton(Button[] button) {
this.button = button;
}
@Override
public String toString() {
return "Menu [button=" + Arrays.toString(button) + "]";
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/qywx/api/menu/vo/CommonButton.java | src/main/java/com/jeecg/qywx/api/menu/vo/CommonButton.java | package com.jeecg.qywx.api.menu.vo;
/**
* 普通按钮(子按钮)
*
* @author zhoujf
* @date 2016-04-05
*/
public class CommonButton extends Button {
private String type;
private String key;
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public String toString() {
return "CommonButton [type=" + type + ", key=" + key + "]";
}
} | java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/oauth2/JdtOauth2API.java | src/main/java/com/jeecg/dingtalk/api/oauth2/JdtOauth2API.java | package com.jeecg.dingtalk.api.oauth2;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.ApiUrls;
import com.jeecg.dingtalk.api.core.util.HttpUtil;
import com.jeecg.dingtalk.api.oauth2.vo.ContactUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 钉钉 Oauth2 接口
*/
public class JdtOauth2API {
private static final Logger logger = LoggerFactory.getLogger(JdtOauth2API.class);
/**
* 获取用户token
*
* @param clientId 应用id。可使用扫码登录应用或者第三方个人小程序的appId。
* @param clientSecret 应用密钥。
* @param code OAuth 2.0 临时授权码。
* @return userAccessToken
*/
public static String getUserAccessToken(String clientId, String clientSecret, String code) {
JSONObject params = new JSONObject();
params.put("clientId", clientId);
params.put("clientSecret", clientSecret);
params.put("code", code);
params.put("grantType", "authorization_code");
String url = ApiUrls.OAUTH2_USER_ACCESS_TOKEN;
JSONObject response = HttpUtil.sendPost(url, params.toJSONString());
logger.info("[GET_USER_ACCESS_TOKEN] response:{}", new Object[]{JSON.toJSONString(response)});
if (response != null) {
String accessToken = response.getString("accessToken");
if (accessToken != null && accessToken.length() > 0) {
return accessToken;
}
}
return null;
}
/**
* 获取用户通讯录个人信息
* 调用本接口获取企业用户通讯录中的个人信息。
*
* @param unionId 用户的unionId。 如需获取当前授权人的信息,unionId参数可以传me。
* @param accessToken 调用服务端接口的授权凭证。使用个人用户的accessToken
* @return ContactUser
*/
public static ContactUser getContactUsers(String unionId, String accessToken) {
String url = ApiUrls.get(ApiUrls.OAUTH2_CONTACT_USERS, unionId);
JSONObject headers = new JSONObject();
headers.put("x-acs-dingtalk-access-token", accessToken);
JSONObject json = HttpUtil.httpRequest(url, "GET", null, headers);
if (json != null) {
logger.info("[GET_CONTACT_USERS] response:{}", new Object[]{json.toJSONString()});
return json.toJavaObject(ContactUser.class);
}
logger.error("[GET_CONTACT_USERS] response: null");
return null;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/oauth2/vo/ContactUser.java | src/main/java/com/jeecg/dingtalk/api/oauth2/vo/ContactUser.java | package com.jeecg.dingtalk.api.oauth2.vo;
/**
* 获取用户通讯录个人信息,返回用户信息
*
* @author sunjianlei
*/
public class ContactUser {
// 用户的钉钉昵称。
private String nick;
// 头像URL。
private String avatarUrl;
// 用户的手机号。
// 说明 如果要获取用户手机号,需要在开发者后台申请个人手机号信息权限
private String mobile;
// 用户的openId。
private String openId;
// 用户的unionId。
private String unionId;
// 用户的个人邮箱。
private String email;
// 手机号对应的国家号。
private String stateCode;
public String getNick() {
return nick;
}
public ContactUser setNick(String nick) {
this.nick = nick;
return this;
}
public String getAvatarUrl() {
return avatarUrl;
}
public ContactUser setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
return this;
}
public String getMobile() {
return mobile;
}
public ContactUser setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public String getOpenId() {
return openId;
}
public ContactUser setOpenId(String openId) {
this.openId = openId;
return this;
}
public String getUnionId() {
return unionId;
}
public ContactUser setUnionId(String unionId) {
this.unionId = unionId;
return this;
}
public String getEmail() {
return email;
}
public ContactUser setEmail(String email) {
this.email = email;
return this;
}
public String getStateCode() {
return stateCode;
}
public ContactUser setStateCode(String stateCode) {
this.stateCode = stateCode;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/base/JdtBaseAPI.java | src/main/java/com/jeecg/dingtalk/api/base/JdtBaseAPI.java | package com.jeecg.dingtalk.api.base;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.vo.AccessToken;
import com.jeecg.dingtalk.api.core.util.ApiUrls;
import com.jeecg.dingtalk.api.core.util.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 钉钉基础接口
*
* @author sunjianlei
*/
public class JdtBaseAPI {
private static final Logger logger = LoggerFactory.getLogger(JdtBaseAPI.class);
/**
* 获取access_token
* <br>
* https://developers.dingtalk.com/document/app/obtain-orgapp-token
*
* @param appKey 应用的唯一标识key
* @param appSecret 应用的密钥
* @return AccessToken
*/
public static AccessToken getAccessToken(String appKey, String appSecret) {
AccessToken accessToken = null;
String url = ApiUrls.get(ApiUrls.ACCESS_TOKEN, appKey, appSecret);
JSONObject response = HttpUtil.sendGet(url);
// 如果请求成功
if (response != null) {
try {
String access_token = response.getString("access_token");
int expires_in = response.getIntValue("expires_in");
accessToken = new AccessToken(access_token, expires_in);
logger.info("[ACCESS_TOKEN] 获取ACCESS_TOKEN成功:{}", new Object[]{accessToken});
} catch (Exception e) {
// 获取token失败
int errcode = response.getIntValue("errcode");
String errmsg = response.getString("errmsg");
logger.info("[ACCESS_TOKEN] 获取ACCESS_TOKEN失败 errcode:{} errmsg:{}", new Object[]{errcode, errmsg});
}
}
return accessToken;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/JdtUserAPI.java | src/main/java/com/jeecg/dingtalk/api/user/JdtUserAPI.java | package com.jeecg.dingtalk.api.user;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.response.Response;
import com.jeecg.dingtalk.api.core.util.ApiUrls;
import com.jeecg.dingtalk.api.core.util.HttpUtil;
import com.jeecg.dingtalk.api.core.util.JdtTypes;
import com.jeecg.dingtalk.api.core.vo.PageResult;
import com.jeecg.dingtalk.api.user.body.GetUserListBody;
import com.jeecg.dingtalk.api.user.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 钉钉用户接口
*
* @author sunjianlei
*/
public class JdtUserAPI {
private static final Logger logger = LoggerFactory.getLogger(JdtUserAPI.class);
/**
* 创建用户
* <br>
* https://developers.dingtalk.com/document/app/user-information-creation
*
* @param user 用户实例
* @param accessToken 有效的access_token
* @return Response<String> 成功返回userid
*/
public static Response<String> create(User user, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_CREATE, accessToken);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(user));
Response<String> response = new Response<>(originResponse);
if (response.isSuccess()) {
// 将常用的userId直接返回(实际上也就只有这一个返回参数)
String userid = originResponse.getResult().getString("userid");
response.setResult(userid);
}
logger.info("[USER_CREATE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 更新用户信息
* <br>
* https://developers.dingtalk.com/document/app/user-information-update
*
* @param user 用户实例
* @param accessToken 有效的access_token
* @return Response<JSONObject>
*/
public static Response<JSONObject> update(User user, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_UPDATE, accessToken);
Response<JSONObject> response = HttpUtil.post(url, JSON.toJSONString(user));
logger.info("[USER_UPDATE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 删除用户
* <br>
* https://developers.dingtalk.com/document/app/delete-a-user
*
* @param userid 用户唯一标识userid
* @param accessToken 有效的access_token
* @return Response<JSONObject>
*/
public static Response<JSONObject> delete(String userid, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_DELETE, accessToken);
JSONObject body = new JSONObject();
body.put("userid", userid);
Response<JSONObject> response = HttpUtil.post(url, body.toJSONString());
logger.info("[USER_DELETE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 伪批量删除用户(for循环调接口)
*
* @param userIds 用户ID列表
* @param accessToken 有效的access_token
* @return List<Response<JSONObject>>
*/
public static List<Response<JSONObject>> batchDeletePseudo(Collection<String> userIds, String accessToken) {
List<Response<JSONObject>> list = new ArrayList<>();
int result = 0;
for (String userId : userIds) {
list.add(JdtUserAPI.delete(userId, accessToken));
}
return list;
}
/**
* 根据userid获取用户详情
* <br>
* https://developers.dingtalk.com/document/app/query-user-details
*
* @param userid 用户唯一标识userid
* @param accessToken 有效的access_token
* @return Response<User>
*/
public static Response<User> getUserById(String userid, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_GET, accessToken);
JSONObject body = new JSONObject();
body.put("userid", userid);
Response<User> response = HttpUtil.post(url, body.toJSONString(), User.class);
logger.info("[USER_GET_BY_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取部门用户详情。说明:只获取当前部门下的员工信息,不包含子部门内的员工。
* <br>
* https://developers.dingtalk.com/document/app/queries-the-complete-information-of-a-department-user
*
* @param body GetUserListBody实例
* @param accessToken 有效的access_token
* @return Response<PageResult<User>> 分页对象
*/
public static Response<PageResult<User>> getUserListByDeptId(GetUserListBody body, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_LIST, accessToken);
Response<PageResult<User>> response = HttpUtil.post(url, JSON.toJSONString(body), JdtTypes.PageResult_User);
logger.info("[USER_GET_LIST_BY_DEPT_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取部门用户基础信息。<br>
* 调用本接口获取指定部门的用户userid和name。<br>
* 说明:只获取当前部门下的员工信息,不包含子部门内的员工。
* <br>
* https://developers.dingtalk.com/document/app/queries-the-complete-information-of-a-department-user
*
* @param body GetUserListBody实例
* @param accessToken 有效的access_token
* @return Response<PageResult<User>> 分页对象
*/
public static Response<PageResult<User>> getUserListSimpleByDeptId(GetUserListBody body, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_LIST_SIMPLE, accessToken);
Response<PageResult<User>> response = HttpUtil.post(url, JSON.toJSONString(body), JdtTypes.PageResult_User);
logger.info("[USER_GET_LIST_SIMPLE_BY_DEPT_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取部门用户userid列表。
* <br>
* 注意:目前暂不支持一次性获取企业下所有员工userid值,如果开发者希望获取企业下所有员工userid值,可以通过以下方法:<br>
* 1. 调用“获取部门列表”接口,通过逐级遍历,获取该企业下所有部门ID。<br>
* 2. 调用本接口,分别获取每个部门下的员工userid。<br>
* <br>
* https://developers.dingtalk.com/document/app/query-the-list-of-department-userids
*
* @param deptId deptId
* @param accessToken 有效的access_token
* @return Response<List<String>>
*/
public static Response<List<String>> getUserListIdByDeptId(int deptId, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_LIST_ID, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", deptId);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(body));
Response<List<String>> response = new Response<>(originResponse);
if (response.isSuccess()) {
List<String> userid_list = originResponse.getResult().getJSONArray("userid_list").toJavaList(String.class);
response.setResult(userid_list);
}
logger.info("[USER_GET_LIST_ID_BY_DEPT_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取员工人数
* <br>
* 调用本接口获取员工人数。
* <br>
* https://developers.dingtalk.com/document/app/obtain-the-number-of-employees-v2
*
* @param onlyActive 是否包含未激活钉钉人数。
* false:包含未激活钉钉的人员数量。
* true:只包含激活钉钉的人员数量。
* @param accessToken 有效的access_token
* @return Response<Integer>
*/
public static Response<Integer> getUserCount(boolean onlyActive, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_COUNT, accessToken);
JSONObject body = new JSONObject();
body.put("only_active", onlyActive);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(body));
Response<Integer> response = new Response<>(originResponse);
if (response.isSuccess()) {
response.setResult(originResponse.getResult().getIntValue("count"));
}
logger.info("[USER_COUNT] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取员工人数,包含未激活钉钉的人员数量
*
* @return Response<Integer>
*/
public static Response<Integer> getUserCount(String accessToken) {
return JdtUserAPI.getUserCount(false, accessToken);
}
/**
* 根据手机号获取userid
* <br>
* https://developers.dingtalk.com/document/app/query-users-by-phone-number
*
* @param mobile 用户的手机号。
* @param accessToken 有效的access_token
* @return Response<String>
*/
public static Response<String> getUseridByMobile(String mobile, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_GET_ID_BY_MOBILE, accessToken);
JSONObject body = new JSONObject();
body.put("mobile", mobile);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(body));
Response<String> response = new Response<>(originResponse);
if (response.isSuccess()) {
// 将常用的userId直接返回(实际上也就只有这一个返回参数)
String userid = originResponse.getResult().getString("userid");
response.setResult(userid);
}
logger.info("[USER_GET_ID_BY_MOBILE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 根据unionid获取用户userid
* <br>
* https://developers.dingtalk.com/document/app/query-a-user-by-the-union-id
*
* @param unionid 员工在当前开发者企业账号范围内的唯一标识,系统生成,不会改变。
* @param accessToken 有效的access_token
* @return Response<String>
*/
public static Response<String> getUseridByUnionid(String unionid, String accessToken) {
String url = ApiUrls.get(ApiUrls.USER_GET_ID_BY_UNIONID, accessToken);
JSONObject body = new JSONObject();
body.put("unionid", unionid);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(body));
Response<String> response = new Response<>(originResponse);
if (response.isSuccess()) {
// 将常用的userId直接返回(实际上也就只有这一个返回参数)
String userid = originResponse.getResult().getString("userid");
response.setResult(userid);
}
logger.info("[USER_GET_ID_BY_UNIONID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/body/GetUserListBody.java | src/main/java/com/jeecg/dingtalk/api/user/body/GetUserListBody.java | package com.jeecg.dingtalk.api.user.body;
/**
* 获取用户列表接口所需参数
*
* @author sunjianlei
*/
public class GetUserListBody {
/**
* 部门ID,根部门ID为1。必填
*/
private int dept_id;
/**
* 分页查询的游标,最开始传0,后续传返回参数中的next_cursor值
*/
private int cursor;
/**
* 分页大小
*/
private int size;
/**
* 部门成员的排序规则,默认不传是按自定义排序(custom):
* <br>
* entry_asc:代表按照进入部门的时间升序
* <br>
* entry_desc:代表按照进入部门的时间降序
* <br>
* modify_asc:代表按照部门信息修改时间升序
* <br>
* modify_desc:代表按照部门信息修改时间降序
* <br>
* custom:代表用户定义(未定义时按照拼音)排序
*/
private String order_field;
/**
* 是否返回访问受限的员工。
*/
private Boolean contain_access_limit;
/**
* 通讯录语言,取值。
* <br>
* zh_CN:中文(默认值)。
* <br>
* en_US:英文。
*/
private String language;
public GetUserListBody(int dept_id, int cursor, int size) {
this.dept_id = dept_id;
this.cursor = cursor;
this.size = size;
}
public int getDept_id() {
return dept_id;
}
public int getCursor() {
return cursor;
}
public int getSize() {
return size;
}
public String getOrder_field() {
return order_field;
}
public GetUserListBody setOrder_field(String order_field) {
this.order_field = order_field;
return this;
}
public Boolean getContain_access_limit() {
return contain_access_limit;
}
public GetUserListBody setContain_access_limit(Boolean contain_access_limit) {
this.contain_access_limit = contain_access_limit;
return this;
}
public String getLanguage() {
return language;
}
public GetUserListBody setLanguage(String language) {
this.language = language;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/UserRole.java | src/main/java/com/jeecg/dingtalk/api/user/vo/UserRole.java | package com.jeecg.dingtalk.api.user.vo;
/**
* 角色
*
* @author sunjianlei
*/
public class UserRole {
/**
* 角色ID
*/
private Number id;
/**
* 角色名称
*/
private String name;
/**
* 角色组名称
*/
private String group_name;
public Number getId() {
return id;
}
public UserRole setId(Number id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public UserRole setName(String name) {
this.name = name;
return this;
}
public String getGroup_name() {
return group_name;
}
public UserRole setGroup_name(String group_name) {
this.group_name = group_name;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/DeptOrder.java | src/main/java/com/jeecg/dingtalk/api/user/vo/DeptOrder.java | package com.jeecg.dingtalk.api.user.vo;
/**
* 员工在对应的部门中的排序
*
* @author sunjianlei
*/
public class DeptOrder {
/**
* 部门ID
*/
private Number dept_id;
/**
* 员工在部门中的排序
*/
private Number order;
public Number getDept_id() {
return dept_id;
}
public DeptOrder setDept_id(Number dept_id) {
this.dept_id = dept_id;
return this;
}
public Number getOrder() {
return order;
}
public DeptOrder setOrder(Number order) {
this.order = order;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/UnionEmpExt.java | src/main/java/com/jeecg/dingtalk/api/user/vo/UnionEmpExt.java | package com.jeecg.dingtalk.api.user.vo;
/**
* 当用户来自于关联组织时的关联信息
*
* @author sunjianlei
*/
public class UnionEmpExt {
/**
* 员工的userid
*/
private String userid;
/**
* 关联映射关系
*/
private UnionEmpMapVo[] union_emp_map_list;
/**
* 当前用户所属的组织的企业corpid
*/
private String corp_id;
public String getUserid() {
return userid;
}
public UnionEmpExt setUserid(String userid) {
this.userid = userid;
return this;
}
public UnionEmpMapVo[] getUnion_emp_map_list() {
return union_emp_map_list;
}
public UnionEmpExt setUnion_emp_map_list(UnionEmpMapVo[] union_emp_map_list) {
this.union_emp_map_list = union_emp_map_list;
return this;
}
public String getCorp_id() {
return corp_id;
}
public UnionEmpExt setCorp_id(String corp_id) {
this.corp_id = corp_id;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/DeptLeader.java | src/main/java/com/jeecg/dingtalk/api/user/vo/DeptLeader.java | package com.jeecg.dingtalk.api.user.vo;
/**
* 员工在对应的部门中是否领导。
*
* @author sunjianlei
*/
public class DeptLeader {
/**
* 部门ID
*/
private Number dept_id;
/**
* 是否是领导
*/
private Boolean leader;
public Number getDept_id() {
return dept_id;
}
public DeptLeader setDept_id(Number dept_id) {
this.dept_id = dept_id;
return this;
}
public Boolean getLeader() {
return leader;
}
public DeptLeader setLeader(Boolean leader) {
this.leader = leader;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/User.java | src/main/java/com/jeecg/dingtalk/api/user/vo/User.java | package com.jeecg.dingtalk.api.user.vo;
import java.util.Arrays;
/**
* 钉钉用户对象
*
* @author sunjianlei
*/
public class User {
/**
* 员工的userid
*/
private String userid;
/**
* 员工在当前开发者企业账号范围内的唯一标识
*/
private String unionid;
/**
* 员工名称
*/
private String name;
/**
* 头像
*/
private String avatar;
/**
* 国际电话区号
*/
private String state_code;
/**
* 员工的直属主管
*/
private String manager_userid;
/**
* 手机号码
*/
private String mobile;
/**
* 是否隐藏号码
*/
private Boolean hide_mobile;
/**
* 分机号
*/
private String telephone;
/**
* 员工工号
*/
private String job_number;
/**
* 职位
*/
private String title;
/**
* 员工邮箱
*/
private String email;
/**
* 办公地点
*/
private String work_place;
/**
* 备注
*/
private String remark;
/**
* 专属帐号登录名
*/
private String login_id;
/**
* 专属帐号类型: sso:企业自建专属帐号;dingtalk:钉钉自建专属帐号
*/
private String exclusive_account_type;
/**
* 是否专属帐号
*/
private Boolean exclusive_account;
/**
* 所属部门ID列表
*/
private String dept_id_list;
/**
* 员工在对应的部门中的排序
*/
private DeptOrder[] dept_order_list;
/**
* 扩展属性,最大长度2000个字符
*/
private String extension;
/**
* 入职时间,Unix时间戳,单位毫秒
*/
private Number hired_date;
/**
* 是否激活了钉钉
*/
private Boolean active;
/**
* 是否完成了实名认证
*/
private Boolean real_authed;
/**
* 是否为企业的高管
*/
private Boolean senior;
/**
* 是否为企业的管理员
*/
private Boolean admin;
/**
* 是否为企业的老板
*/
private Boolean boss;
/**
* 员工在对应的部门中是否领导
*/
private DeptLeader[] leader_in_dept;
/**
* 角色列表
*/
private UserRole[] role_list;
/**
* 当用户来自于关联组织时的关联信息
*/
private UnionEmpExt union_emp_ext;
public String getUserid() {
return userid;
}
public User setUserid(String userid) {
this.userid = userid;
return this;
}
public String getUnionid() {
return unionid;
}
public User setUnionid(String unionid) {
this.unionid = unionid;
return this;
}
public String getName() {
return name;
}
public User setName(String name) {
this.name = name;
return this;
}
public String getAvatar() {
return avatar;
}
public User setAvatar(String avatar) {
this.avatar = avatar;
return this;
}
public String getState_code() {
return state_code;
}
public User setState_code(String state_code) {
this.state_code = state_code;
return this;
}
public String getManager_userid() {
return manager_userid;
}
public User setManager_userid(String manager_userid) {
this.manager_userid = manager_userid;
return this;
}
public String getMobile() {
return mobile;
}
public User setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public Boolean getHide_mobile() {
return hide_mobile;
}
public User setHide_mobile(Boolean hide_mobile) {
this.hide_mobile = hide_mobile;
return this;
}
public String getTelephone() {
return telephone;
}
public User setTelephone(String telephone) {
this.telephone = telephone;
return this;
}
public String getJob_number() {
return job_number;
}
public User setJob_number(String job_number) {
this.job_number = job_number;
return this;
}
public String getTitle() {
return title;
}
public User setTitle(String title) {
this.title = title;
return this;
}
public String getEmail() {
return email;
}
public User setEmail(String email) {
this.email = email;
return this;
}
public String getWork_place() {
return work_place;
}
public User setWork_place(String work_place) {
this.work_place = work_place;
return this;
}
public String getRemark() {
return remark;
}
public User setRemark(String remark) {
this.remark = remark;
return this;
}
public String getLogin_id() {
return login_id;
}
public User setLogin_id(String login_id) {
this.login_id = login_id;
return this;
}
public String getExclusive_account_type() {
return exclusive_account_type;
}
public User setExclusive_account_type(String exclusive_account_type) {
this.exclusive_account_type = exclusive_account_type;
return this;
}
public Boolean getExclusive_account() {
return exclusive_account;
}
public User setExclusive_account(Boolean exclusive_account) {
this.exclusive_account = exclusive_account;
return this;
}
public String getDept_id_list() {
return dept_id_list;
}
public Integer[] getDept_id_listArray() {
if (dept_id_list != null) {
return Arrays.stream(dept_id_list.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
}
return null;
}
public User setDept_id_list(Integer... dept_id_list) {
this.dept_id_list = String.join(",", Arrays.stream(dept_id_list).map(Object::toString).toArray(String[]::new));
return this;
}
public DeptOrder[] getDept_order_list() {
return dept_order_list;
}
public User setDept_order_list(DeptOrder[] dept_order_list) {
this.dept_order_list = dept_order_list;
return this;
}
public String getExtension() {
return extension;
}
public User setExtension(String extension) {
this.extension = extension;
return this;
}
public Number getHired_date() {
return hired_date;
}
public User setHired_date(Number hired_date) {
this.hired_date = hired_date;
return this;
}
public Boolean getActive() {
return active;
}
public User setActive(Boolean active) {
this.active = active;
return this;
}
public Boolean getReal_authed() {
return real_authed;
}
public User setReal_authed(Boolean real_authed) {
this.real_authed = real_authed;
return this;
}
public Boolean getSenior() {
return senior;
}
public User setSenior(Boolean senior) {
this.senior = senior;
return this;
}
public Boolean getAdmin() {
return admin;
}
public User setAdmin(Boolean admin) {
this.admin = admin;
return this;
}
public Boolean getBoss() {
return boss;
}
public User setBoss(Boolean boss) {
this.boss = boss;
return this;
}
public DeptLeader[] getLeader_in_dept() {
return leader_in_dept;
}
public User setLeader_in_dept(DeptLeader[] leader_in_dept) {
this.leader_in_dept = leader_in_dept;
return this;
}
public UserRole[] getRole_list() {
return role_list;
}
public User setRole_list(UserRole[] role_list) {
this.role_list = role_list;
return this;
}
public UnionEmpExt getUnion_emp_ext() {
return union_emp_ext;
}
public User setUnion_emp_ext(UnionEmpExt union_emp_ext) {
this.union_emp_ext = union_emp_ext;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/user/vo/UnionEmpMapVo.java | src/main/java/com/jeecg/dingtalk/api/user/vo/UnionEmpMapVo.java | package com.jeecg.dingtalk.api.user.vo;
/**
* 关联映射关系
*
* @author sunjianlei
*/
public class UnionEmpMapVo {
/**
* 关联分支组织中的员工userid
*/
private String userid;
/**
* 关联分支组织的企业corpid
*/
private String corp_id;
public String getUserid() {
return userid;
}
public UnionEmpMapVo setUserid(String userid) {
this.userid = userid;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/department/JdtDepartmentAPI.java | src/main/java/com/jeecg/dingtalk/api/department/JdtDepartmentAPI.java | package com.jeecg.dingtalk.api.department;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.response.Response;
import com.jeecg.dingtalk.api.core.util.ApiUrls;
import com.jeecg.dingtalk.api.core.util.HttpUtil;
import com.jeecg.dingtalk.api.core.util.JdtTypes;
import com.jeecg.dingtalk.api.department.vo.Department;
import com.jeecg.dingtalk.api.department.vo.DeptParentResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 钉钉部门接口
*
* @author sunjianlei
*/
public class JdtDepartmentAPI {
private static final Logger logger = LoggerFactory.getLogger(JdtDepartmentAPI.class);
/**
* 创建部门
* <br>
* https://developers.dingtalk.com/document/app/create-a-department-v2
*
* @param department 部门实例
* @param accessToken 有效的access_token
* @return Response<String> 成功返回dept_id
*/
public static Response<Integer> create(Department department, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_CREATE, accessToken);
Response<JSONObject> originResponse = HttpUtil.post(url, JSON.toJSONString(department));
Response<Integer> response = new Response<>(originResponse);
if (response.isSuccess()) {
// 将常用的dept_id直接返回(实际上也就只有这一个返回参数)
Integer dept_id = originResponse.getResult().getInteger("dept_id");
response.setResult(dept_id);
}
logger.info("[DEPART_CREATE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 更新部门信息
* <br>
* https://developers.dingtalk.com/document/app/update-a-department-v2
*
* @param department 部门实例
* @param accessToken 有效的access_token
* @return Response<JSONObject>
*/
public static Response<JSONObject> update(Department department, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_UPDATE, accessToken);
Response<JSONObject> response = HttpUtil.post(url, JSON.toJSONString(department));
logger.info("[DEPART_UPDATE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 根据部门ID删除指定部门
* <br>
* https://developers.dingtalk.com/document/app/delete-a-department-v2
*
* @param dept_id 部门id
* @param accessToken 有效的access_token
* @return Response<JSONObject>
*/
public static Response<JSONObject> delete(int dept_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_DELETE, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", dept_id);
Response<JSONObject> response = HttpUtil.post(url, body.toJSONString());
logger.info("[DEPART_DELETE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 伪批量删除部门(for循环调接口)
*
* @param deptIds 部门ID列表
* @param accessToken 有效的access_token
* @return List<Response<JSONObject>>
*/
public static List<Response<JSONObject>> batchDeletePseudo(Collection<Integer> deptIds, String accessToken) {
List<Response<JSONObject>> list = new ArrayList<>();
for (Integer deptId : deptIds) {
list.add(JdtDepartmentAPI.delete(deptId, accessToken));
}
return list;
}
/**
* 获取根部门下的子部门列表(不包含子部门的子部门)
* <br>
* https://developers.dingtalk.com/document/app/obtain-the-department-list-v2
*
* @param accessToken 有效的access_token
* @return Response<List<Department>>
*/
public static Response<List<Department>> listByRoot(String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_LIST_SUB, accessToken);
Response<List<Department>> response = HttpUtil.post(url, "", JdtTypes.List_Department);
logger.info("[DEPART_LIST_ROOT_SUB] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 根据父ID获取子部门列表(不包含子部门的子部门)
* <br>
* https://developers.dingtalk.com/document/app/obtain-the-department-list-v2
*
* @param dept_id 父部门ID
* @param accessToken 有效的access_token
* @return Response<List<Department>>
*/
public static Response<List<Department>> listByParentId(int dept_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_LIST_SUB, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", dept_id);
Response<List<Department>> response = HttpUtil.post(url, body.toJSONString(), JdtTypes.List_Department);
logger.info("[DEPART_LIST_SUB_BY_PARENT_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 根据dept_id获取部门详情
* <br>
* https://developers.dingtalk.com/document/app/query-department-details0-v2
*
* @param dept_id 部门id
* @param accessToken 有效的access_token
* @return Response<Department>
*/
public static Response<Department> getDepartmentById(int dept_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_GET, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", dept_id);
Response<Department> response = HttpUtil.post(url, body.toJSONString(), Department.class);
logger.info("[DEPART_GET_BY_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取子部门ID列表
* <br>
* https://developers.dingtalk.com/document/app/obtain-a-sub-department-id-list-v2
*
* @param dept_id 部门id
* @param accessToken 有效的access_token
* @return Response<List<Integer>> 成功返回子部门id列表
*/
public static Response<List<Integer>> getListSubId(int dept_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_GET_LIST_SUB_ID, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", dept_id);
Response<JSONObject> originResponse = HttpUtil.post(url, body.toJSONString());
Response<List<Integer>> response = new Response<>(originResponse);
if (response.isSuccess()) {
List<Integer> dept_id_list = originResponse.getResult().getJSONArray("dept_id_list").toJavaList(Integer.class);
response.setResult(dept_id_list);
}
logger.info("[DEPART_GET_LIST_SUB_ID] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取指定用户的所有父部门列表
* <br>
* https://developers.dingtalk.com/document/app/queries-the-list-of-all-parent-departments-of-a-user
*
* @param userid 用户id
* @param accessToken 有效的access_token
* @return Response<List<DeptParentResponse>> 成功返回父部门id列表
*/
public static Response<List<DeptParentResponse>> getListParentByUser(String userid, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_GET_LIST_PARENT_BY_USER, accessToken);
JSONObject body = new JSONObject();
body.put("userid", userid);
Response<JSONObject> originResponse = HttpUtil.post(url, body.toJSONString());
Response<List<DeptParentResponse>> response = new Response<>(originResponse);
if (response.isSuccess()) {
List<DeptParentResponse> parent_list = originResponse.getResult().getJSONArray("parent_list").toJavaList(DeptParentResponse.class);
response.setResult(parent_list);
}
logger.info("[DEPART_GET_LIST_PARENT_BY_USER] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 获取指定部门的所有父部门列表
* <br>
* https://developers.dingtalk.com/document/app/query-the-list-of-all-parent-departments-of-a-department
*
* @param dept_id 部门id
* @param accessToken 有效的access_token
* @return Response<List<Integer>> 成功返回父部门id列表
*/
public static Response<List<Integer>> getListParentByDept(String dept_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.DEPART_GET_LIST_PARENT_BY_DEPT, accessToken);
JSONObject body = new JSONObject();
body.put("dept_id", dept_id);
Response<JSONObject> originResponse = HttpUtil.post(url, body.toJSONString());
Response<List<Integer>> response = new Response<>(originResponse);
if (response.isSuccess()) {
List<Integer> parent_id_list = originResponse.getResult().getJSONArray("parent_id_list").toJavaList(Integer.class);
response.setResult(parent_id_list);
}
logger.info("[DEPART_GET_LIST_PARENT_BY_DEPT] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 非官方API接口:获取钉钉的所有部门,平铺返回,不关心失败情况
*
* @param accessToken 有效的access_token
* @return List<Department>
*/
public static List<Department> listAll(String accessToken) {
List<Department> all = new ArrayList<>();
int topDepId = 1;
// 先查出来顶级的部门
Response<Department> response = JdtDepartmentAPI.getDepartmentById(topDepId, accessToken);
if (response.isSuccess()) {
all.add(response.getResult());
JdtDepartmentAPI.listAllGetChildren(topDepId, accessToken, all);
}
return all;
}
/**
* 非官方API接口:获取钉钉的所有部门,平铺返回,返回失败结果
*
* @param accessToken 有效的access_token
* @return List<Response<Department>>
*/
public static List<Response<Department>> listAllResponse(String accessToken) {
List<Response<Department>> res = new ArrayList<>();
List<Department> all = new ArrayList<>();
int topDepId = 1;
// 先查出来顶级的部门
Response<Department> response = JdtDepartmentAPI.getDepartmentById(topDepId, accessToken);
res.add(response);
if (response.isSuccess()) {
all.add(response.getResult());
JdtDepartmentAPI.listAllGetChildren(topDepId, accessToken, all, res);
}
return res;
}
private static void listAllGetChildren(int parentDepId, String accessToken, List<Department> all) {
JdtDepartmentAPI.listAllGetChildren(parentDepId, accessToken, all, null);
}
private static void listAllGetChildren(int parentDepId, String accessToken, List<Department> all, List<Response<Department>> res) {
Response<List<Department>> response = JdtDepartmentAPI.listByParentId(parentDepId, accessToken);
if (response.isSuccess()) {
List<Department> departments = response.getResult();
if (departments.size() != 0) {
all.addAll(departments);
for (Department department : departments) {
if (res != null) {
res.add(new Response<>(response, department));
}
JdtDepartmentAPI.listAllGetChildren(department.getDept_id(), accessToken, all, res);
}
}
} else if (res != null) {
res.add(new Response<>(response));
}
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/department/vo/DeptParentResponse.java | src/main/java/com/jeecg/dingtalk/api/department/vo/DeptParentResponse.java | package com.jeecg.dingtalk.api.department.vo;
/**
* 【返回对象】获取指定用户的所有父部门列表
*
* @author sunjianlei
*/
public class DeptParentResponse {
/**
* 父部门列表。
*/
private Integer[] parent_dept_id_list;
public Integer[] getParent_dept_id_list() {
return parent_dept_id_list;
}
public DeptParentResponse setParent_dept_id_list(Integer[] parent_dept_id_list) {
this.parent_dept_id_list = parent_dept_id_list;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/department/vo/Department.java | src/main/java/com/jeecg/dingtalk/api/department/vo/Department.java | package com.jeecg.dingtalk.api.department.vo;
/**
* 钉钉部门对象
*
* @author sunjianlei
*/
public class Department {
/**
* 部门ID。
*/
private Integer dept_id;
/**
* 部门名称。
*/
private String name;
/**
* 父部门ID。
*/
private Integer parent_id;
/**
* 部门标识字段。
*/
private String source_identifier;
/**
* 是否同步创建一个关联此部门的企业群:
*/
private Boolean create_dept_group;
/**
* 当部门群已经创建后,是否有新人加入部门会自动加入该群:
*/
private Boolean auto_add_user;
/**
* 部门是否来自关联组织:
*/
private Boolean from_union_org;
/**
* 教育部门标签:
*/
private String tags;
/**
* 在父部门中的次序值。
*/
private Integer order;
/**
* 部门群ID。
*/
private String dept_group_chat_id;
/**
* 部门群是否包含子部门:
*/
private Boolean group_contain_sub_dept;
/**
* 企业群群主ID。
*/
private String org_dept_owner;
/**
* 部门的主管列表。
*/
private String[] dept_manager_userid_list;
/**
* 是否限制本部门成员查看通讯录:
*/
private Boolean outer_dept;
/**
* 当限制部门成员的通讯录查看范围时(即outer_dept为true时),配置的部门员工可见部门列表。
*/
private Integer[] outer_permit_depts;
/**
* 本部门成员是否只能看到所在部门及下级部门通讯录:
* <p>
* true:只能看到所在部门及下级部门通讯录
* <p>
* false:不能查看所有通讯录,在通讯录中仅能看到自己
* <p>
* 当outer_dept为true时,此参数生效。
*/
private Boolean outer_dept_only_self;
/**
* 当限制部门成员的通讯录查看范围时(即outer_dept为true时),配置的部门员工可见员工列表。
*/
private String[] outer_permit_users;
/**
* 是否隐藏本部门:
*/
private Boolean hide_dept;
/**
* 当隐藏本部门时(即hide_dept为true时),配置的允许在通讯录中查看本部门的员工列表。
*/
private String[] user_permits;
/**
* 隐藏本部门时(即hide_dept为true时),配置的允许在通讯录中查看本部门的部门列表。
*/
private Integer[] dept_permits;
public Integer getDept_id() {
return dept_id;
}
public Department setDept_id(Integer dept_id) {
this.dept_id = dept_id;
return this;
}
public String getName() {
return name;
}
public Department setName(String name) {
this.name = name;
return this;
}
public Integer getParent_id() {
return parent_id;
}
public Department setParent_id(Integer parent_id) {
this.parent_id = parent_id;
return this;
}
public String getSource_identifier() {
return source_identifier;
}
public Department setSource_identifier(String source_identifier) {
this.source_identifier = source_identifier;
return this;
}
public Boolean getCreate_dept_group() {
return create_dept_group;
}
public Department setCreate_dept_group(Boolean create_dept_group) {
this.create_dept_group = create_dept_group;
return this;
}
public Boolean getAuto_add_user() {
return auto_add_user;
}
public Department setAuto_add_user(Boolean auto_add_user) {
this.auto_add_user = auto_add_user;
return this;
}
public Boolean getFrom_union_org() {
return from_union_org;
}
public Department setFrom_union_org(Boolean from_union_org) {
this.from_union_org = from_union_org;
return this;
}
public String getTags() {
return tags;
}
public Department setTags(String tags) {
this.tags = tags;
return this;
}
public Integer getOrder() {
return order;
}
public Department setOrder(Integer order) {
this.order = order;
return this;
}
public String getDept_group_chat_id() {
return dept_group_chat_id;
}
public Department setDept_group_chat_id(String dept_group_chat_id) {
this.dept_group_chat_id = dept_group_chat_id;
return this;
}
public Boolean getGroup_contain_sub_dept() {
return group_contain_sub_dept;
}
public Department setGroup_contain_sub_dept(Boolean group_contain_sub_dept) {
this.group_contain_sub_dept = group_contain_sub_dept;
return this;
}
public String getOrg_dept_owner() {
return org_dept_owner;
}
public Department setOrg_dept_owner(String org_dept_owner) {
this.org_dept_owner = org_dept_owner;
return this;
}
public String[] getDept_manager_userid_list() {
return dept_manager_userid_list;
}
public Department setDept_manager_userid_list(String[] dept_manager_userid_list) {
this.dept_manager_userid_list = dept_manager_userid_list;
return this;
}
public Boolean getOuter_dept() {
return outer_dept;
}
public Department setOuter_dept(Boolean outer_dept) {
this.outer_dept = outer_dept;
return this;
}
public Integer[] getOuter_permit_depts() {
return outer_permit_depts;
}
public Department setOuter_permit_depts(Integer[] outer_permit_depts) {
this.outer_permit_depts = outer_permit_depts;
return this;
}
public String[] getOuter_permit_users() {
return outer_permit_users;
}
public Department setOuter_permit_users(String[] outer_permit_users) {
this.outer_permit_users = outer_permit_users;
return this;
}
public Boolean getHide_dept() {
return hide_dept;
}
public Department setHide_dept(Boolean hide_dept) {
this.hide_dept = hide_dept;
return this;
}
public String[] getUser_permits() {
return user_permits;
}
public Department setUser_permits(String[] user_permits) {
this.user_permits = user_permits;
return this;
}
public Integer[] getDept_permits() {
return dept_permits;
}
public Department setDept_permits(Integer[] dept_permits) {
this.dept_permits = dept_permits;
return this;
}
public Boolean getOuter_dept_only_self() {
return outer_dept_only_self;
}
public Department setOuter_dept_only_self(Boolean outer_dept_only_self) {
this.outer_dept_only_self = outer_dept_only_self;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/JdtMessageAPI.java | src/main/java/com/jeecg/dingtalk/api/message/JdtMessageAPI.java | package com.jeecg.dingtalk.api.message;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.response.Response;
import com.jeecg.dingtalk.api.core.util.ApiUrls;
import com.jeecg.dingtalk.api.core.util.HttpUtil;
import com.jeecg.dingtalk.api.message.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 钉钉消息通知接口
* <p>
* 发送工作通知消息需要注意以下事项:
* <p>
* 同一个应用相同消息的内容同一个用户一天只能接收一次。
* <p>
* 同一个应用给同一个用户发送消息,企业内部应用一天不得超过500次。
* <p>
* 通过设置to_all_user参数全员推送消息,一天最多3次。
* <p>
* 超出以上限制次数后,接口返回成功,但用户无法接收到。详细的限制说明,请参考工作通知消息限制。
* <p>
* 该接口是异步发送消息,接口返回成功并不表示用户一定会收到消息,需要通过获取工作通知消息的发送结果接口查询是否给用户发送成功。
* <p>
* 消息类型和样例可参考消息类型与数据格式。
*
* @author sunjianlei
*/
public class JdtMessageAPI {
private static final Logger logger = LoggerFactory.getLogger(JdtMessageAPI.class);
/**
* 发送消息
*/
private static <T extends SuperMessage> Response<String> sendMessage(Message<T> message, String accessToken, String logText) {
String url = ApiUrls.get(ApiUrls.MSG_ASYNC_SEND, accessToken);
logger.info("[" + logText + "] params:{}", new Object[]{JSON.toJSONString(message)});
JSONObject originResponse = HttpUtil.sendPost(url, JSON.toJSONString(message));
Response<String> response = new Response<>(originResponse);
if (response.isSuccess()) {
// 将常用的task_id直接返回(实际上也就只有这一个返回参数)
String task_id = originResponse.getString("task_id");
response.setResult(task_id);
}
logger.info("[" + logText + "] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
/**
* 发送文本消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 文本消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendTextMessage(Message<TextMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_TEXT_MESSAGE");
}
/**
* 发送图片消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 图片消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendImageMessage(Message<ImageMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_IMAGE_MESSAGE");
}
/**
* 发送语音消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 语音消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendVoiceMessage(Message<VoiceMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_VOICE_MESSAGE");
}
/**
* 发送文件消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 文件消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendFileMessage(Message<FileMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_FILE_MESSAGE");
}
/**
* 发送链接消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 链接消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendLinkMessage(Message<LinkMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_LINK_MESSAGE");
}
/**
* 发送Markdown消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message Markdown消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendMarkdownMessage(Message<MarkdownMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_MARKDOWN_MESSAGE");
}
/**
* 发送卡片消息
* <br>
* https://developers.dingtalk.com/document/app/asynchronous-sending-of-enterprise-session-messages
*
* @param message 卡片消息
* @param accessToken 有效的access_token
* @return Response<String> 成功返回task_id(任务id,可用于撤回)
*/
public static Response<String> sendActionCardMessage(Message<ActionCardMessage> message, String accessToken) {
return JdtMessageAPI.sendMessage(message, accessToken, "MSG_SEND_ACTION_CARD_MESSAGE");
}
/**
* 撤回消息。仅支持撤回24小时内的工作消息通知。<br>
* https://developers.dingtalk.com/document/app/notification-of-work-withdrawal
*
* @param agent_id 发送消息时使用的微应用的ID。
* @param msg_task_id 发送消息时钉钉返回的任务ID。
* @param accessToken 有效的access_token
* @return Response<JSONObject>
*/
public static Response<JSONObject> recallMessage(String agent_id, String msg_task_id, String accessToken) {
String url = ApiUrls.get(ApiUrls.MSG_RECALL, accessToken);
JSONObject body = new JSONObject();
body.put("agent_id", agent_id);
body.put("msg_task_id", msg_task_id);
Response<JSONObject> response = HttpUtil.post(url, body.toJSONString());
logger.info("[MSG_RECALL_MESSAGE] response:{}", new Object[]{JSON.toJSONString(response)});
return response;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/MarkdownMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/MarkdownMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉Markdown消息
*
* @author sunjianlei
*/
public class MarkdownMessage extends SuperMessage {
private JSONObject markdown = new JSONObject();
/**
* 钉钉Markdown消息
*
* @param title 首屏会话透出的展示内容。
* @param text markdown格式的消息,建议500字符以内。
*/
public MarkdownMessage(String title, String text) {
super(MessageType.MARKDOWN);
this.markdown.put("title", title);
this.markdown.put("text", text);
}
public JSONObject getMarkdown() {
return this.markdown;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/Message.java | src/main/java/com/jeecg/dingtalk/api/message/vo/Message.java | package com.jeecg.dingtalk.api.message.vo;
import java.util.Arrays;
import java.util.Collection;
/**
* 钉钉消息
*
* @author sunjianlei
*/
public class Message<T extends SuperMessage> {
/**
* 发送消息时使用的微应用的AgentID。
*/
private String agent_id;
/**
* 接收者的userid列表,最大用户列表长度100。
*/
private Collection<String> userid_list;
/**
* 接收者的部门id列表,最大列表长度20。 接收者是部门ID时,包括子部门下的所有用户。
*/
private Collection<String> dept_id_list;
/**
* 是否发送给企业全部用户。当设置为false时必须指定userid_list或dept_id_list其中一个参数的值。
*/
private Boolean to_all_user;
/**
* 消息内容,最长不超过2048个字节
*/
private T msg;
public Message(Integer agent_id, T msg) {
this.agent_id = String.valueOf(agent_id);
this.msg = msg;
}
public Message(String agent_id, T msg) {
this.agent_id = agent_id;
this.msg = msg;
}
public String getAgent_id() {
return agent_id;
}
public String getUserid_list() {
if (userid_list != null) {
return String.join(",", userid_list);
}
return null;
}
public Message setUserid_list(Collection<String> userid_list) {
this.userid_list = userid_list;
return this;
}
public Message setUserid_list(String... userid_list) {
this.userid_list = Arrays.asList(userid_list);
return this;
}
public String getDept_id_list() {
if (dept_id_list != null) {
return String.join(",", dept_id_list);
}
return null;
}
public Message setDept_id_list(Collection<String> dept_id_list) {
this.dept_id_list = dept_id_list;
return this;
}
public Message setDept_id_list(String... dept_id_list) {
this.dept_id_list = Arrays.asList(dept_id_list);
return this;
}
public Boolean getTo_all_user() {
return to_all_user;
}
public Message setTo_all_user(Boolean to_all_user) {
this.to_all_user = to_all_user;
return this;
}
public T getMsg() {
return msg;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/LinkMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/LinkMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉链接消息
*
* @author sunjianlei
*/
public class LinkMessage extends SuperMessage {
private JSONObject link = new JSONObject();
/**
* 钉钉链接消息
*
* @param messageUrl 消息点击链接地址
* @param picUrl 图片地址,可以通过上传媒体文件接口获取。
* @param title 消息标题,建议100字符以内。
* @param text 消息描述,建议500字符以内。
*/
public LinkMessage(String messageUrl, String picUrl, String title, String text) {
super(MessageType.LINK);
this.link.put("messageUrl", messageUrl);
this.link.put("picUrl", picUrl);
this.link.put("title", title);
this.link.put("text", text);
}
public JSONObject getLink() {
return this.link;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/ImageMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/ImageMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉图片消息
*
* @author sunjianlei
*/
public class ImageMessage extends SuperMessage {
private JSONObject image = new JSONObject();
/**
* 钉钉图片消息
*
* @param media_id 媒体文件 media_id。可以通过上传媒体文件接口获取。建议宽600像素 x 400像素,宽高比3 : 2。
*/
public ImageMessage(String media_id) {
super(MessageType.IMAGE);
this.image.put("media_id", media_id);
}
public JSONObject getImage() {
return this.image;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/TextMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/TextMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉文本消息
*
* @author sunjianlei
*/
public class TextMessage extends SuperMessage {
private JSONObject text = new JSONObject();
/**
* 钉钉文本消息
*
* @param content 消息内容
*/
public TextMessage(String content) {
super(MessageType.TEXT);
this.text.put("content", content);
}
public JSONObject getText() {
return this.text;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/FileMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/FileMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉文件消息
*
* @author sunjianlei
*/
public class FileMessage extends SuperMessage {
private JSONObject file = new JSONObject();
/**
* 钉钉文件消息
*
* @param media_id 媒体文件ID。 引用的媒体文件最大10MB。可以通过上传媒体文件接口获取。
*/
public FileMessage(String media_id) {
super(MessageType.FILE);
this.file.put("media_id", media_id);
}
public JSONObject getFile() {
return this.file;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/VoiceMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/VoiceMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉语音消息
*
* @author sunjianlei
*/
public class VoiceMessage extends SuperMessage {
private JSONObject voice = new JSONObject();
/**
* 钉钉语音消息
*
* @param media_id 媒体文件ID。可以通过上传媒体文件接口获取。
* @param duration 音频时长,正整数,小于60
*/
public VoiceMessage(String media_id, int duration) {
super(MessageType.VOICE);
this.voice.put("media_id", media_id);
this.voice.put("duration", duration);
}
public JSONObject getVoice() {
return this.voice;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/ActionCardMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/ActionCardMessage.java | package com.jeecg.dingtalk.api.message.vo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeecg.dingtalk.api.core.util.MessageType;
/**
* 钉钉卡片消息
*
* @author sunjianlei
*/
public class ActionCardMessage extends SuperMessage {
private JSONObject action_card = new JSONObject();
/**
* 钉钉卡片消息
*
* @param markdown 消息内容,支持markdown,语法参考标准markdown语法。建议1000个字符以内。
*/
public ActionCardMessage(String markdown) {
super(MessageType.ACTION_CARD);
this.action_card.put("markdown", markdown);
}
public JSONObject getAction_card() {
return this.action_card;
}
public ActionCardMessage put(String key, Object value) {
this.action_card.put(key, value);
return this;
}
/**
* 使用整体跳转ActionCard样式时的标题。
*/
public ActionCardMessage setTitle(String title) {
return this.put("title", title);
}
/**
* 使用整体跳转ActionCard样式时的标题。必须与single_url同时设置,最长20个字符。
* <br>
* 如果是整体跳转的ActionCard样式,则single_title和single_url必须设置。
*/
public ActionCardMessage setSingle_title(String single_title) {
return this.put("single_title", single_title);
}
/**
* 使用整体跳转ActionCard样式时的标题。必须与single_url同时设置,最长20个字符。
* <br>
* 如果是整体跳转的ActionCard样式,则single_title和single_url必须设置。
*/
public ActionCardMessage setSingle_url(String single_url) {
return this.put("single_url", single_url);
}
/**
* 使用独立跳转ActionCard样式时的按钮排列方式:
* <p>
* 0:竖直排列
* <p>
* 1:横向排列
* <p>
* 必须与btn_json_list同时设置。
*/
public ActionCardMessage setBtn_orientation(String btn_orientation) {
return this.put("btn_orientation", btn_orientation);
}
/**
* 使用独立跳转ActionCard样式时的按钮列表;必须与btn_orientation同时设置,且长度不超过1000字符。
*
* @param title 使用独立跳转ActionCard样式时的按钮的标题,最长20个字符。
* @param action_url 使用独立跳转ActionCard样式时的跳转链接。
*/
public ActionCardMessage setBtn_json_list(String title, String action_url) {
JSONArray btn_json_list = this.action_card.getJSONArray("btn_json_list");
if (btn_json_list == null) {
btn_json_list = new JSONArray();
this.action_card.put("btn_json_list", btn_json_list);
}
JSONObject item = new JSONObject();
item.put("title", title);
item.put("action_url", action_url);
btn_json_list.add(item);
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/message/vo/SuperMessage.java | src/main/java/com/jeecg/dingtalk/api/message/vo/SuperMessage.java | package com.jeecg.dingtalk.api.message.vo;
/**
* 钉钉消息超类
*
* @author sunjianlei
*/
public class SuperMessage {
protected SuperMessage(String msgtype) {
this.msgtype = msgtype;
}
private String msgtype;
public String getMsgtype() {
return msgtype;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/util/ApiUrls.java | src/main/java/com/jeecg/dingtalk/api/core/util/ApiUrls.java | package com.jeecg.dingtalk.api.core.util;
/**
* 钉钉Api接口地址
*
* @author sunjianlei
*/
public class ApiUrls {
// ========================= JdtBaseAPI =========================
/**
* 【GET】获取 access_token,appKey,appSecret
*/
public final static String ACCESS_TOKEN = "https://oapi.dingtalk.com/gettoken?appkey=%s&appsecret=%s";
// ========================= JdtUserAPI =========================
/**
* 【POST】创建用户:access_token
*/
public final static String USER_CREATE = "https://oapi.dingtalk.com/topapi/v2/user/create?access_token=%s";
/**
* 【POST】更新用户信息:access_token
*/
public final static String USER_UPDATE = "https://oapi.dingtalk.com/topapi/v2/user/update?access_token=%s";
/**
* 【POST】删除用户:access_token
*/
public final static String USER_DELETE = "https://oapi.dingtalk.com/topapi/v2/user/delete?access_token=%s";
/**
* 【POST】根据userid获取用户详情:access_token
*/
public final static String USER_GET = "https://oapi.dingtalk.com/topapi/v2/user/get?access_token=%s";
/**
* 【POST】获取部门用户详细信息:access_token
*/
public final static String USER_LIST = "https://oapi.dingtalk.com/topapi/v2/user/list?access_token=%s";
/**
* 【POST】获取部门用户基础信息:access_token
*/
public final static String USER_LIST_SIMPLE = "https://oapi.dingtalk.com/topapi/user/listsimple?access_token=%s";
/**
* 【POST】获取部门用户userid列表:access_token
*/
public final static String USER_LIST_ID = "https://oapi.dingtalk.com/topapi/user/listid?access_token=%s";
/**
* 【POST】获取员工人数:access_token
*/
public final static String USER_COUNT = "https://oapi.dingtalk.com/topapi/user/count?access_token=%s";
/**
* 【POST】根据手机号获取userid:access_token
*/
public final static String USER_GET_ID_BY_MOBILE = "https://oapi.dingtalk.com/topapi/v2/user/getbymobile?access_token=%s";
/**
* 【POST】根据unionid获取用户userid:access_token
*/
public final static String USER_GET_ID_BY_UNIONID = "https://oapi.dingtalk.com/topapi/user/getbyunionid?access_token=%s";
// ========================= JdtDepartmentAPI =========================
/**
* 【POST】创建部门:access_token
*/
public final static String DEPART_CREATE = "https://oapi.dingtalk.com/topapi/v2/department/create?access_token=%s";
/**
* 【POST】更新部门:access_token
*/
public final static String DEPART_UPDATE = "https://oapi.dingtalk.com/topapi/v2/department/update?access_token=%s";
/**
* 【POST】根据部门ID删除指定部门:access_token
*/
public final static String DEPART_DELETE = "https://oapi.dingtalk.com/topapi/v2/department/delete?access_token=%s";
/**
* 【POST】根据部门ID获取子部门列表:access_token
*/
public final static String DEPART_LIST_SUB = "https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=%s";
/**
* 【POST】根据部门ID获取指定部门详情:access_token
*/
public final static String DEPART_GET = "https://oapi.dingtalk.com/topapi/v2/department/get?access_token=%s";
/**
* 【POST】获取子部门ID列表:access_token
*/
public final static String DEPART_GET_LIST_SUB_ID = "https://oapi.dingtalk.com/topapi/v2/department/listsubid?access_token=%s";
/**
* 【POST】获取指定用户的所有父部门列表:access_token
*/
public final static String DEPART_GET_LIST_PARENT_BY_USER = "https://oapi.dingtalk.com/topapi/v2/department/listparentbyuser?access_token=%s";
/**
* 【POST】获取指定部门的所有父部门列表:access_token
*/
public final static String DEPART_GET_LIST_PARENT_BY_DEPT = "https://oapi.dingtalk.com/topapi/v2/department/listparentbydept?access_token=%s";
// ========================= JdtMessageAPI =========================
/**
* 【POST】发送工作通知:access_token
*/
public final static String MSG_ASYNC_SEND = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=%s";
/**
* 【POST】撤回工作通知消息:access_token
*/
public final static String MSG_RECALL = "https://oapi.dingtalk.com/topapi/message/corpconversation/recall?access_token=%s";
// ========================= JdtOauth2API =========================
/**
* 【POST】获取用户token
*/
public final static String OAUTH2_USER_ACCESS_TOKEN = "https://api.dingtalk.com/v1.0/oauth2/userAccessToken";
/**
* 【GET】获取用户通讯录个人信息:unionId
*/
public final static String OAUTH2_CONTACT_USERS = "https://api.dingtalk.com/v1.0/contact/users/%s";
// ========================= 辅助方法 =========================
/**
* 获取URL,自动替换参数
*/
public static String get(String url, Object... args) {
return String.format(url, args);
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/util/HttpUtil.java | src/main/java/com/jeecg/dingtalk/api/core/util/HttpUtil.java | package com.jeecg.dingtalk.api.core.util;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson2.JSONFactory;
import com.jeecg.dingtalk.api.core.response.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author zhoujf
*
*/
public class HttpUtil {
private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
/**
* http get请求
* @param url
* @return
*/
public static JSONObject sendGet(String url) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"GET",null);
return jsonObject;
}
/**
* http post请求
* @param url
* @return
*/
public static JSONObject sendPost(String url) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"POST",null);
return jsonObject;
}
/**
* http post请求
* @param url
* @param output json串
* @return
*/
public static JSONObject sendPost(String url,String output) {
JSONObject jsonObject = null;
jsonObject = httpRequest(url,"POST",output);
return jsonObject;
}
/**
* http post请求
* @param url 请求地址
* @param output json串
*/
public static <T> Response<T> post(String url, String output, Type... types) {
JSONObject json = httpRequest(url, "POST", output);
return toJavaObject(json, new TypeReference<Response<T>>(types){});
}
/**
* 重写fastjson的toJavaObject方法
* 解决问题: “ class com.alibaba.fastjson2.JSONObject cannot be cast to class com.alibaba.fastjson.JSONObject ”
* @param json
* @param typeReference
* @return
* @param <T>
*/
public static <T> T toJavaObject(JSONObject json, TypeReference<T> typeReference) {
Type type = (Type)(typeReference != null ? typeReference.getType() : Object.class);
if (type instanceof Class) {
return json.toJavaObject(typeReference);
} else {
String str = com.alibaba.fastjson.JSON.toJSONString(json);
return (T)com.alibaba.fastjson.JSON.parseObject(str, type);
}
}
public static JSONObject httpRequest(String request, String requestMethod, String output) {
return httpRequest(request, requestMethod, output, null);
}
/**
* 发起https请求并获取结果
*
* @param request 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param output 提交的数据
* @param headers 请求头
* @return JSONObject(通过JSONObject.get ( key)的方式获取json对象的属性值)
*/
public static JSONObject httpRequest(String request, String requestMethod, String output, JSONObject headers) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
try {
logger.debug("[HTTP] http请求request:{},method:{},output{}", new Object[]{request,requestMethod,output});
//建立连接
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(3000);
connection.setReadTimeout(30000);
connection.setUseCaches(false);
connection.setRequestMethod(requestMethod);
// begin 设置请求头
if (headers != null && headers.size() > 0) {
for (String key : headers.keySet()) {
connection.setRequestProperty(key, headers.getString(key));
}
}
if ("POST".equalsIgnoreCase(requestMethod)) {
connection.setRequestProperty("Accept", "application/json;charset=UTF-8");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
}
// end 设置请求头
if(output!=null){
OutputStream out = connection.getOutputStream();
out.write(output.getBytes("UTF-8"));
out.close();
}
//流处理
inputStream = connection.getInputStream();
inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
reader = new BufferedReader(inputStreamReader);
String line;
while((line=reader.readLine())!=null){
buffer.append(line);
}
//关闭连接、释放资源
reader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
connection.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
logger.error("[HTTP] http请求error:{}", new Object[]{e.getMessage()});
}finally {
// 使用finally块来关闭输出流、输入流
try {
if (reader != null) {
reader.close();
}
if(inputStreamReader!=null){
inputStreamReader.close();
}
if(inputStream!=null){
inputStream.close();
}
} catch (Exception ex) {
ex.printStackTrace();
logger.error("[HTTP] http请求error:{}", new Object[]{ex.getMessage()});
}
}
return jsonObject;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/util/JdtTypes.java | src/main/java/com/jeecg/dingtalk/api/core/util/JdtTypes.java | package com.jeecg.dingtalk.api.core.util;
import com.alibaba.fastjson.TypeReference;
import com.jeecg.dingtalk.api.core.vo.PageResult;
import com.jeecg.dingtalk.api.department.vo.Department;
import com.jeecg.dingtalk.api.user.vo.User;
import java.lang.reflect.Type;
import java.util.List;
/**
* 用于JSON泛型转换,定义各种实际类型
*
* @author sunjianlei
*/
public class JdtTypes {
public final static Type PageResult_User = new TypeReference<PageResult<User>>() {
}.getType();
public final static Type PageResult_Department = new TypeReference<PageResult<Department>>() {
}.getType();
public final static Type List_String = new TypeReference<List<String>>() {
}.getType();
public final static Type List_Department = new TypeReference<List<Department>>() {
}.getType();
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/util/MessageType.java | src/main/java/com/jeecg/dingtalk/api/core/util/MessageType.java | package com.jeecg.dingtalk.api.core.util;
/**
* 钉钉消息类型
*
* @author sunjianlei
*/
public class MessageType {
/**
* 文本消息
*/
public static final String TEXT = "text";
/**
* 图片消息
*/
public static final String IMAGE = "image";
/**
* 语音消息
*/
public static final String VOICE = "voice";
/**
* 文件消息
*/
public static final String FILE = "file";
/**
* 链接消息
*/
public static final String LINK = "link";
/**
* Markdown消息
*/
public static final String MARKDOWN = "markdown";
/**
* 卡片消息
*/
public static final String ACTION_CARD = "action_card";
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/vo/AccessToken.java | src/main/java/com/jeecg/dingtalk/api/core/vo/AccessToken.java | package com.jeecg.dingtalk.api.core.vo;
/**
* 钉钉应用AccessToken
*
* @author sunjianlei
*/
public class AccessToken {
/**
* 获取到的accessToken
*/
private String accessToken;
/**
* accessToken有效时间,单位:秒
*/
private int expiresIn;
public AccessToken(String accessToken, int expiresIn) {
this.accessToken = accessToken;
this.expiresIn = expiresIn;
}
public String getAccessToken() {
return accessToken;
}
public int getExpiresIn() {
return expiresIn;
}
public String toString() {
return "AccessToken [accessToken=" + accessToken + ", expiresIn=" + expiresIn + "]";
}
} | java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/vo/PageResult.java | src/main/java/com/jeecg/dingtalk/api/core/vo/PageResult.java | package com.jeecg.dingtalk.api.core.vo;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* 分页返回结果
*
* @author sunjianlei
*/
public class PageResult<T> {
/**
* 是否还有更多的数据
*/
private Boolean has_more;
/**
* 下一次分页的游标,如果has_more为false,表示没有更多的分页数据。
*/
private Integer next_cursor;
/**
* 结果列表
*/
private List<T> list;
public PageResult() {
}
public PageResult(JSONObject json, Class<T> clazz) {
this.has_more = json.getBoolean("has_more");
this.next_cursor = json.getInteger("next_cursor");
this.list = json.getJSONArray("list").toJavaList(clazz);
}
public Boolean getHas_more() {
return has_more;
}
public PageResult<T> setHas_more(Boolean has_more) {
this.has_more = has_more;
return this;
}
public Integer getNext_cursor() {
return next_cursor;
}
public PageResult<T> setNext_cursor(Integer next_cursor) {
this.next_cursor = next_cursor;
return this;
}
public List<T> getList() {
return list;
}
public PageResult<T> setList(List<T> list) {
this.list = list;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/dingtalk/api/core/response/Response.java | src/main/java/com/jeecg/dingtalk/api/core/response/Response.java | package com.jeecg.dingtalk.api.core.response;
import com.alibaba.fastjson.JSONObject;
/**
* API返回
*
* @author sunjianlei
*/
public class Response<T> {
/**
* 请求ID。
*/
private String request_id;
/**
* 返回码。
*/
private Integer errcode;
/**
* 调用失败时返回的错误信息。
*/
private String errmsg;
/**
* 返回结果。
*/
private T result;
public Response() {
}
public Response(Response origin) {
this.request_id = origin.request_id;
this.errcode = origin.errcode;
this.errmsg = origin.errmsg;
}
public Response(Response origin, T result) {
this.request_id = origin.request_id;
this.errcode = origin.errcode;
this.errmsg = origin.errmsg;
this.result = result;
}
public Response(JSONObject origin) {
this.request_id = origin.getString("request_id");
this.errcode = origin.getInteger("errcode");
this.errmsg = origin.getString("errmsg");
}
/**
* 当前请求是否成功
*/
public boolean isSuccess() {
if (this.errcode == null) {
return false;
}
return this.errcode == 0;
}
public String getRequest_id() {
return request_id;
}
public Response<T> setRequest_id(String request_id) {
this.request_id = request_id;
return this;
}
public Integer getErrcode() {
return errcode;
}
public Response<T> setErrcode(Integer errcode) {
this.errcode = errcode;
return this;
}
public String getErrmsg() {
return errmsg;
}
public Response<T> setErrmsg(String errmsg) {
this.errmsg = errmsg;
return this;
}
public T getResult() {
return result;
}
public Response<T> setResult(T result) {
this.result = result;
return this;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/dto/WeiBoMentionsDto.java | src/main/java/com/jeecg/weibo/dto/WeiBoMentionsDto.java | package com.jeecg.weibo.dto;
public class WeiBoMentionsDto {
//采用OAuth授权方式为必填参数,OAuth授权后获得。
private String access_token ;
//若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
private String since_id ;
//若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
private String max_id;
//单页返回的记录条数,最大不超过200,默认为20。
private String count;
//返回结果的页码,默认为1。
private String page ;
//作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
private String filter_by_author;
//来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。
private String filter_by_source;
//原创筛选类型,0:全部微博、1:原创的微博,默认为0。
private String filter_by_type;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getSince_id() {
return since_id;
}
public void setSince_id(String since_id) {
this.since_id = since_id;
}
public String getMax_id() {
return max_id;
}
public void setMax_id(String max_id) {
this.max_id = max_id;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getFilter_by_author() {
return filter_by_author;
}
public void setFilter_by_author(String filter_by_author) {
this.filter_by_author = filter_by_author;
}
public String getFilter_by_source() {
return filter_by_source;
}
public void setFilter_by_source(String filter_by_source) {
this.filter_by_source = filter_by_source;
}
public String getFilter_by_type() {
return filter_by_type;
}
public void setFilter_by_type(String filter_by_type) {
this.filter_by_type = filter_by_type;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MentionsDto [access_token=");
builder.append(access_token);
builder.append(", since_id=");
builder.append(since_id);
builder.append(", max_id=");
builder.append(max_id);
builder.append(", count=");
builder.append(count);
builder.append(", page=");
builder.append(page);
builder.append(", filter_by_author=");
builder.append(filter_by_author);
builder.append(", filter_by_source=");
builder.append(filter_by_source);
builder.append(", filter_by_type=");
builder.append(filter_by_type);
builder.append("]");
return builder.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java | src/main/java/com/jeecg/weibo/dto/WeiboSendDto.java | package com.jeecg.weibo.dto;
import com.alipay.api.internal.util.StringUtils;
import java.net.URLEncoder;
/**
* 发布微博
* @author Administrator
*
*/
public class WeiboSendDto {
//采用OAuth授权方式为必填参数,OAuth授权后获得
String access_token;
//要发布的微博文本内容,必须做URLencode,内容不超过140个汉字。
String status;
//图片的URL地址,必须以http开头。
String url;
//微博id
String id;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getStatus() {
String encode = "";
if(!StringUtils.isEmpty(status)){
encode = URLEncoder.encode(status);
}
return encode;
}
public void setStatus(String status) {
this.status = status;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WeiboSendDto [access_token=");
builder.append(access_token);
builder.append(", status=");
builder.append(status);
builder.append(", url=");
builder.append(url);
builder.append(", id=");
builder.append(id);
builder.append("]");
return builder.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/dto/WeiboFollowersDto.java | src/main/java/com/jeecg/weibo/dto/WeiboFollowersDto.java | package com.jeecg.weibo.dto;
public class WeiboFollowersDto {
//采用OAuth授权方式为必填参数,OAuth授权后获得。
private String access_token;
//需要查询的用户UID。
private String uid;
//需要查询的用户昵称。
private String screen_name;
//单页返回的记录条数,默认为50,最大不超过200。
private String count;
//返回结果的游标,下一页用返回值里的next_cursor,上一页用previous_cursor,默认为0。
private String cursor;
//返回值中user字段中的status字段开关,0:返回完整status字段、1:status字段仅返回status_id,默认为1。
private String trim_status;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getScreen_name() {
return screen_name;
}
public void setScreen_name(String screen_name) {
this.screen_name = screen_name;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String getTrim_status() {
return trim_status;
}
public void setTrim_status(String trim_status) {
this.trim_status = trim_status;
}
public String getCursor() {
return cursor;
}
public void setCursor(String cursor) {
this.cursor = cursor;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WeiboFollowersDto [access_token=");
builder.append(access_token);
builder.append(", uid=");
builder.append(uid);
builder.append(", screen_name=");
builder.append(screen_name);
builder.append(", count=");
builder.append(count);
builder.append(", trim_status=");
builder.append(trim_status);
builder.append(", cursor=");
builder.append(cursor);
builder.append("]");
return builder.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/dto/WeiboUserTimelineDto.java | src/main/java/com/jeecg/weibo/dto/WeiboUserTimelineDto.java | package com.jeecg.weibo.dto;
public class WeiboUserTimelineDto {
// 采用OAuth授权方式为必填参数,OAuth授权后获得
private String access_token ;
//需要查询的用户ID
private String uid;
//需要查询的用户昵称
private String screen_name;
//若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0
private String since_id;
//若指定此参数,则返回ID小于或等于max_id的微博,默认为0
private String max_id;
//单页返回的记录条数,最大不超过100,超过100以100处理,默认为20
private String count;
//返回结果的页码,默认为1
private String page;
//是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0
private String base_app;
//过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0
private String feature;
//返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0
private String trim_user;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getScreen_name() {
return screen_name;
}
public void setScreen_name(String screen_name) {
this.screen_name = screen_name;
}
public String getSince_id() {
return since_id;
}
public void setSince_id(String since_id) {
this.since_id = since_id;
}
public String getMax_id() {
return max_id;
}
public void setMax_id(String max_id) {
this.max_id = max_id;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getBase_app() {
return base_app;
}
public void setBase_app(String base_app) {
this.base_app = base_app;
}
public String getFeature() {
return feature;
}
public void setFeature(String feature) {
this.feature = feature;
}
public String getTrim_user() {
return trim_user;
}
public void setTrim_user(String trim_user) {
this.trim_user = trim_user;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UserTimelineDto [access_token=");
builder.append(access_token);
builder.append(", uid=");
builder.append(uid);
builder.append(", screen_name=");
builder.append(screen_name);
builder.append(", since_id=");
builder.append(since_id);
builder.append(", max_id=");
builder.append(max_id);
builder.append(", count=");
builder.append(count);
builder.append(", page=");
builder.append(page);
builder.append(", base_app=");
builder.append(base_app);
builder.append(", feature=");
builder.append(feature);
builder.append(", trim_user=");
builder.append(trim_user);
builder.append("]");
return builder.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java | src/main/java/com/jeecg/weibo/util/WeiboStatusesUtil.java | package com.jeecg.weibo.util;
import com.alipay.api.internal.util.StringUtils;
import com.jeecg.weibo.dto.WeiBoMentionsDto;
import com.jeecg.weibo.dto.WeiboUserTimelineDto;
import com.jeecg.weibo.exception.BusinessException;
public class WeiboStatusesUtil {
/*
*
* 验证获取用户发布的微博的请求必填参数验证
*/
public static void getUserTimelineParmValidate (WeiboUserTimelineDto userTimeline){
if(StringUtils.isEmpty(userTimeline.getAccess_token())){
throw new BusinessException("access_token 不能 为空");
}
}
/*
*
* 拼接获取用户发布的微博的请求路径
*/
public static String getUserTimelineUrl (String interUrl,WeiboUserTimelineDto userTimeline){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(userTimeline.getAccess_token())){
requestUrl.append("&access_token="+userTimeline.getAccess_token());
}
if(!StringUtils.isEmpty(userTimeline.getUid())){
requestUrl.append("&uid="+userTimeline.getUid());
}
if(!StringUtils.isEmpty(userTimeline.getScreen_name())){
requestUrl.append("&screen_name="+userTimeline.getScreen_name());
}
if(!StringUtils.isEmpty(userTimeline.getSince_id())){
requestUrl.append("&since_id="+userTimeline.getSince_id());
}
if(!StringUtils.isEmpty(userTimeline.getMax_id())){
requestUrl.append("&max_id="+userTimeline.getMax_id());
}
if(!StringUtils.isEmpty(userTimeline.getCount())){
requestUrl.append("&count="+userTimeline.getCount());
}
if(!StringUtils.isEmpty(userTimeline.getPage())){
requestUrl.append("&page="+userTimeline.getPage());
}
if(!StringUtils.isEmpty(userTimeline.getBase_app())){
requestUrl.append("&base_app="+userTimeline.getBase_app());
}
if(!StringUtils.isEmpty(userTimeline.getFeature())){
requestUrl.append("&feature="+userTimeline.getFeature());
}
if(!StringUtils.isEmpty(userTimeline.getTrim_user())){
requestUrl.append("trim_user="+userTimeline.getTrim_user());
}
return requestUrl.toString();
}
/*
*
* 验证获取用户发布的微博的请求必填参数验证
*/
public static void getUserTimelineIdsParmValidate (WeiboUserTimelineDto userTimeline){
if(StringUtils.isEmpty(userTimeline.getAccess_token())){
throw new BusinessException("access_token不能为空");
}
if(StringUtils.isEmpty(userTimeline.getUid())&&(StringUtils.isEmpty(userTimeline.getScreen_name()))){
throw new BusinessException("uid与screen_name二者不能全为空");
}
if(!StringUtils.isEmpty(userTimeline.getUid())&&(!StringUtils.isEmpty(userTimeline.getScreen_name()))){
throw new BusinessException("uid与screen_name二者只能选其一");
}
}
/*
*
* 验证批量获取指定微博的转发数评论数的请求必填参数验证
*/
public static void getCountParmValidate(String access_token,String ids){
if(StringUtils.isEmpty(access_token)){
throw new BusinessException("access_token不能为空");
}
if(StringUtils.isEmpty(ids)){
throw new BusinessException("微博ID不能为空");
}else{
String [] idArry=ids.split(",");
if(idArry.length>100){
throw new BusinessException("微博ID个数不能超过100");
}
}
}
/*
*
* 拼接获取用户发布的微博的请求路径
*/
public static String getCountUrl (String interUrl,String access_token,String ids){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(access_token)){
requestUrl.append("&access_token="+access_token);
}
if(!StringUtils.isEmpty(ids)){
requestUrl.append("&ids="+ids);
}
return requestUrl.toString();
}
/*
*
* 根据ID获取单条微博信息的请求必填参数验证
*/
public static void getShowParmValidate(String access_token,String id){
if(StringUtils.isEmpty(access_token)){
throw new BusinessException("access_token不能为空");
}
if(StringUtils.isEmpty(id)){
throw new BusinessException("微博ID不能为空");
}else{
String [] idArry=id.split(",");
if(idArry.length>1){
throw new BusinessException("微博ID个数只能为1");
}
}
}
/*
*
* 根据ID获取单条微博信息的请求路径
*/
public static String getShowUrl (String interUrl,String access_token,String id){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(access_token)){
requestUrl.append("&access_token="+access_token);
}
if(!StringUtils.isEmpty(id)){
requestUrl.append("&id="+id);
}
return requestUrl.toString();
}
/*
*
* 获取@当前用户的最新微博的请求必填参数验证
*
*/
public static void getMentionsParmValidate(WeiBoMentionsDto mentions){
if(StringUtils.isEmpty(mentions.getAccess_token())){
throw new BusinessException("access_token不能为空");
}
}
/*
*
* 获取@当前用户的最新微博的请求路径
*/
public static String getMentionsUrl (String interUrl,WeiBoMentionsDto mentions){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(mentions.getAccess_token())){
requestUrl.append("&access_token="+mentions.getAccess_token());
}
if(!StringUtils.isEmpty(mentions.getSince_id())){
requestUrl.append("&since_id="+mentions.getSince_id());
}
if(!StringUtils.isEmpty(mentions.getMax_id())){
requestUrl.append("&max_id="+mentions.getMax_id());
}
if(!StringUtils.isEmpty(mentions.getCount())){
requestUrl.append("&count="+mentions.getCount());
}
if(!StringUtils.isEmpty(mentions.getPage())){
requestUrl.append("&page="+mentions.getPage());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_author())){
requestUrl.append("&filter_by_author="+mentions.getFilter_by_author());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_source())){
requestUrl.append("&filter_by_source="+mentions.getFilter_by_source());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_type())){
requestUrl.append("&filter_by_type="+mentions.getFilter_by_type());
}
return requestUrl.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/util/HttpUtil.java | src/main/java/com/jeecg/weibo/util/HttpUtil.java | package com.jeecg.weibo.util;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class HttpUtil {
/**
* 发起https请求并获取结果
*
* @param requestUrl
* 请求地址
* @param requestMethod
* 请求方式(GET、POST)
* @param outputStr
* 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public static JSONObject httpRequest(String requestUrl,
String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
HttpURLConnection httpUrlConn = null;
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
URL url = new URL(requestUrl);
httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
//HttpURLConnection设置网络超时
httpUrlConn.setConnectTimeout(4500);
httpUrlConn.setReadTimeout(4500);
// httpUrlConn.setRequestProperty("content-type", "text/html");
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
// jsonObject = JSONObject.fromObject(buffer.toString());
} catch (ConnectException ce) {
} catch (Exception e) {
}finally{
try {
httpUrlConn.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
}
return jsonObject;
}
/**
* 发起https请求并获取结果
*
* @param requestUrl
* 请求地址
* @param requestMethod
* 请求方式(GET、POST)
* @param outputStr
* 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public static JSONArray httpRequestArr(String requestUrl,
String requestMethod, String outputStr) {
JSONArray jsonArray = null;
StringBuffer buffer = new StringBuffer();
HttpURLConnection httpUrlConn = null;
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
URL url = new URL(requestUrl);
httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
//HttpURLConnection设置网络超时
httpUrlConn.setConnectTimeout(4500);
httpUrlConn.setReadTimeout(4500);
// httpUrlConn.setRequestProperty("content-type", "text/html");
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
System.out.println(buffer.toString());
jsonArray = JSONArray.parseArray(buffer.toString());
// jsonObject = JSONObject.parseObject(buffer.toString());
// jsonObject = JSONObject.fromObject(buffer.toString());
} catch (ConnectException ce) {
} catch (Exception e) {
}finally{
try {
httpUrlConn.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
}
return jsonArray;
}
/**
* 发起https请求并获取结果
*
* @param requestUrl
* 请求地址
* @param requestMethod
* 请求方式(GET、POST)
* @param outputStr
* 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public static JSONObject httpUploadRequest(String requestUrl,
String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
HttpURLConnection httpUrlConn = null;
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
URL url = new URL(requestUrl);
httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
//HttpURLConnection设置网络超时
httpUrlConn.setConnectTimeout(4500);
httpUrlConn.setReadTimeout(4500);
httpUrlConn.setRequestProperty("content-type", "multipart/form-data");
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
// jsonObject = JSONObject.fromObject(buffer.toString());
} catch (ConnectException ce) {
} catch (Exception e) {
}finally{
try {
httpUrlConn.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
}
return jsonObject;
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
jeecgboot/weixin4j | https://github.com/jeecgboot/weixin4j/blob/9a0a503cc99e24c77de671890fae15ee3235669f/src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java | src/main/java/com/jeecg/weibo/util/WeiboCommentsUtil.java | package com.jeecg.weibo.util;
import com.alipay.api.internal.util.StringUtils;
import com.jeecg.weibo.dto.WeiBoMentionsDto;
import com.jeecg.weibo.exception.BusinessException;
public class WeiboCommentsUtil {
/*
*
* 获取@当前用户的最新微博的请求必填参数验证
*
*/
public static void getBymeParmValidate(WeiBoMentionsDto mentions){
if(StringUtils.isEmpty(mentions.getAccess_token())){
throw new BusinessException("access_token不能为空");
}
}
/*
*
* 获取@当前用户的最新微博的请求路径
*/
public static String getBymeUrl (String interUrl,WeiBoMentionsDto mentions){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(mentions.getAccess_token())){
requestUrl.append("&access_token="+mentions.getAccess_token());
}
if(!StringUtils.isEmpty(mentions.getSince_id())){
requestUrl.append("&since_id="+mentions.getSince_id());
}
if(!StringUtils.isEmpty(mentions.getMax_id())){
requestUrl.append("&max_id="+mentions.getMax_id());
}
if(!StringUtils.isEmpty(mentions.getCount())){
requestUrl.append("&count="+mentions.getCount());
}
if(!StringUtils.isEmpty(mentions.getPage())){
requestUrl.append("&page="+mentions.getPage());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_source())){
requestUrl.append("&filter_by_source="+mentions.getFilter_by_source());
}
return requestUrl.toString();
}
/*
*
* 获取@当前用户的最新微博的请求路径
*/
public static String getTomeUrl (String interUrl,WeiBoMentionsDto mentions){
StringBuilder requestUrl=new StringBuilder();
requestUrl.append(interUrl);
if(!StringUtils.isEmpty(mentions.getAccess_token())){
requestUrl.append("&access_token="+mentions.getAccess_token());
}
if(!StringUtils.isEmpty(mentions.getSince_id())){
requestUrl.append("&since_id="+mentions.getSince_id());
}
if(!StringUtils.isEmpty(mentions.getMax_id())){
requestUrl.append("&max_id="+mentions.getMax_id());
}
if(!StringUtils.isEmpty(mentions.getCount())){
requestUrl.append("&count="+mentions.getCount());
}
if(!StringUtils.isEmpty(mentions.getPage())){
requestUrl.append("&page="+mentions.getPage());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_author())){
requestUrl.append("&filter_by_author="+mentions.getFilter_by_author());
}
if(!StringUtils.isEmpty(mentions.getFilter_by_source())){
requestUrl.append("&filter_by_source="+mentions.getFilter_by_source());
}
return requestUrl.toString();
}
}
| java | Apache-2.0 | 9a0a503cc99e24c77de671890fae15ee3235669f | 2026-01-05T02:41:50.789942Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.