微信公众号开发之——群发视频消息

微信公众号开发群发视频消息笔记(在微信公众号各项功能开通的情况下):
1、首先是上传视频素材
接口:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
说明:在这里插入图片描述
参数说明:(结合示例代码)
其中的参数access_token和type获取到直接拼接到url中就可以
media中放的是所需要上传的文件。
示例代码(自己写的,不怎么完善,不喜勿喷):

public WeiXinResultUrl<MdlUpload> video1(HttpServletRequest request, String accessToken, String type, MultipartFile file) throws Exception{
    String upload_url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE";
    WeiXinResultUrl<MdlUpload> result = new WeiXinResultUrl<MdlUpload>();

    try {
        File toFile = WxMessageUtils.uploadingFile(request,file);
        String url = upload_url.replace("ACCESS_TOKEN", accessToken).replace("TYPE", type);
        JSONObject jsonObject;
        HttpPostUtil post = new HttpPostUtil(url);
        post.addParameter("media", toFile);
        String s = post.send();//post请求到微信的上传地址
        jsonObject = JSONObject.fromObject(s);
        if (jsonObject.containsKey("media_id")) {//判断返回来的数据
            MdlUpload upload=new MdlUpload();//返回数据封装到MdlUpload 类中
            upload.setMedia_id(jsonObject.getString("media_id"));//
            upload.setType(jsonObject.getString("type"));
            upload.setCreated_at(jsonObject.getString("created_at"));
            result.setObj(upload);
            result.setErrmsg("success");
            result.setErrcode("0");
        } else {
            result.setErrmsg(jsonObject.getString("errmsg"));
            result.setErrcode(jsonObject.getString("errcode"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        result.setErrmsg("Upload Exception:"+e.toString());
    }
    return result;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值