| | |
| | | package com.hx.mp.util; |
| | | |
| | | import com.hx.util.corp.entity.AppLetInfo; |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.util.HttpMethodUtil; |
| | | import com.hx.util.StringUtils; |
| | | import net.sf.json.JSONException; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.util.SystemOutLogger; |
| | | |
| | | import java.io.OutputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.text.MessageFormat; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 企业微信工具类 |
| | |
| | | public static final String URL_INFO_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={0}&userid={1}"; |
| | | /**发送消息*/ |
| | | public static final String URL_MESSAGE_SEND = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="; |
| | | |
| | | |
| | | /** |
| | | * 添加工作人员 |
| | |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | | * 添加工作人员 |
| | | * @param at 访问at |
| | | * @param userId 用户id |
| | | * @param name 名称 |
| | | * @param depId 部门id |
| | | * @param position 职位 |
| | | * @param tel 电话 |
| | | * @param email 邮箱 |
| | | * @return 返回 |
| | | */ |
| | | public static JSONObject addUserObj(String at, String userId, String name, int depId |
| | | , String position,String tel,String email) { |
| | | |
| | | if(StringUtils.isEmpty(tel)&&StringUtils.isEmpty(email)){ |
| | | throw new TipsException("添加企业微信手机号和邮箱不能都为空!"); |
| | | } |
| | | |
| | | JSONObject obj = new JSONObject(); |
| | | obj.put("userid", userId); |
| | | obj.put("name", name); |
| | | obj.put("department", depId); |
| | | obj.put("position", position); |
| | | obj.put("mobile", tel); |
| | | obj.put("email", email); |
| | | obj = HttpURLUtil(MessageFormat.format(URL_ADD_USER, at), obj.toString()); |
| | | |
| | | if(obj == null){ |
| | | obj = new JSONObject(); |
| | | } |
| | | |
| | | return obj; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 更新工作人员 |
| | | * @param at 访问at |
| | |
| | | /** |
| | | * 删除工作人员 |
| | | * @param at 访问at |
| | | * @param userId 用户id |
| | | * @param userId 企业用户id |
| | | * @return 返回 |
| | | */ |
| | | public static int deleteUser(String at, String userId) { |
| | |
| | | obj.put("userid", userId); |
| | | |
| | | obj = HttpURLUtil(MessageFormat.format(URL_INFO_USER, at,userId), obj.toString()); |
| | | System.out.println("userId:"+userId); |
| | | System.out.println("obj:"+obj.toString()); |
| | | |
| | | if(obj != null) { |
| | | return obj.optInt("errcode", -1); |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | | * 获取企业用户信息 |
| | | * @param at 访问at |
| | | * @param userId 用户id |
| | | * @return 返回 |
| | | */ |
| | | public static JSONObject userData(String at, String userId) { |
| | | JSONObject obj = new JSONObject(); |
| | | obj.put("userid", userId); |
| | | |
| | | return obj = HttpURLUtil(MessageFormat.format(URL_INFO_USER, at,userId), obj.toString()); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | return obj; |
| | | } |
| | | |
| | | } |