企业微信更换头像

企业微信更换头像

步骤:
1、appid、应用secret
2、获取access_token
3、根据access_token调用企微上传媒体库接口
4、根据人员标识字段更换人员头像

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.utils.IOUtils;
import com.mehow.hklink.service.impl.QywxLinkServiceImpl;
import com.mehow.hklink.utils.maycur.HttpRequest;
import org.apache.commons.codec.Charsets;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class WxLinkUtil {
   



	final static String APPID="xxxxxxxx";
   
    /**
     * 企业微信应用secret
     */
    final static String ORGSECRT="xxxxxxxx";

    private static Logger log = LoggerFactory.getLogger(WxLinkUtil.class);


    private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36";



	
	/**
     * AccessToken获取
     * @param
     * @throws IOException
     * @throws NoSuchAlgorithmException
     * @throws NoSuchProviderException
     * @throws KeyManagementException
     */
    public static JSONObject getOrgAccessToken() throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException{
   
        // 微信secret 业务
        //String requestTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+APPID+"&corpsecret="+ORGSECRT+"";
       // requestTokenUrl = requestTokenUrl.replace("APPID", APPID);
       // requestTokenUrl = requestTokenUrl.replace("SECRET", ORGSECRT);
        StringBuffer jsonObjectToken = CommonHttpUtil.httpsRequest("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+APPID+"&corpsecret="+ORGSECRT+"", "GET", null);
       // JSONObject jsonObject = JSONObject.parseObject(jsonObjectToken.toString());
       // System.out.println("---jsonObject-->>"+jsonObject);
        return JSONObject.parseObject(jsonObjectToken.toString());
    }




    /**
     * 上传临时素材
     * 素材上传得到media_id,该media_id仅三天内有效
     * media_id在同一企业内应用之间可以共享
     * 图片(image):10MB,支持JPG,PNG格式
     * 语音(voice) :2MB,播放长度不超过60s,仅支持AMR格式
     * 视频(video) :10MB,支持MP4格式
     * 普通文件(file):20MB
     * @param access_token
     * @param file 需要上传的文件
     * @param type 文件类型
     * @throws IOException
     */
    public static String uploadMedia(String access_token , File file, String type,String params) throws IOException {
   
        String url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
        url = url.replace("ACCESS_TOKEN",access_token).
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值