如何实现微信 主动发送消息微信消息

如何实现主动发送微信消息_百度知道
如何实现主动发送微信消息
提问者采纳
点你的好友,点一下,然后下面有个小建盘,然后是界面,然后就打字
然后就想发短信
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁我们要使用主动推送消息功能: 即使用微信服务号主动发送消息给某个微信用户, 想问: 怎样才能得到这样的接口? - 微信公众平台开发者问答系统
我们要使用主动推送消息功能: 即使用微信服务号主动发送消息给某个微信用户, 想问: 怎样才能得到这样的接口?
2013年 11月 25日
(140 积分)
我们要使用主动推送消息功能: 即使用微信服务号主动发送消息给某个微信用户,
想问: 怎样才能得到这样的接口?
这样的接口肯定是有的, 因为招商银行信用卡服务号已具备此功能了.
不能回答已答过的问题、已关闭的问题和你自己的提问3个回答
2013年 11月 25日
(27,530 积分)
招行什么的肯定有特殊接口的,如果你只是普通客户的话就不用想了。如果足够NB的话,让腾讯给你更特殊的接口都有可能。
2013年 11月 25日
(470 积分)
只要关注你就可以给他发信息了,但目前只能发文字信息。图文的只有回复才能看到,具体了解可以查看云南氟业的案例,帐户:ynfuye1999
2013年 11月 26日
(240 积分)在微信开发中,利用微信的接口主动给微信关注用户发送消息。这个主要是利用微信的客服接口来实现该功能,具体的实现如下:
& & &* 微信公共账号发送给账号
& & &* @param content 文本内容
& & &* @param toUser 微信用户 &
& & &* @return
& & public &void sendTextMessageToUser(String content,String toUser){
& & & &String json = &{\&touser\&: \&&+toUser+&\&,\&msgtype\&: \&text\&, \&text\&: {\&content\&: \&&+content+&\&}}&;
& & & &//获取access_token
& & & &GetExistAccessToken getExistAccessToken = GetExistAccessToken.getInstance();
& & & &String accessToken = getExistAccessToken.getExistAccessToken();
& & & &//获取请求路径
& & & &String action = &https://api./cgi-bin/message/custom/send?access_token=&+accessT
& & & &System.out.println(&json:&+json);
& & & &try {
& & & & & &connectWeiXinInterface(action,json);
& & & &} catch (Exception e) {
& & & & & &e.printStackTrace();
& & &* 微信公共账号发送给账号(本方法限制使用的消息类型是语音或者图片)
& & &* @param mediaId 图片或者语音内容
& & &* @param toUser 微信用户 &
& & &* @param messageType 消息类型
& & &* @return
& & public &void sendPicOrVoiceMessageToUser(String mediaId,String toUser,String msgType){
& & & & String json=
& & & & if(msgType.equals(REQ_MESSAGE_TYPE_IMAGE)){
& & & & & & &json = &{\&touser\&: \&&+toUser+&\&,\&msgtype\&: \&image\&, \&image\&: {\&media_id\&: \&&+mediaId+&\&}}&;
& & & & }else if(msgType.equals(REQ_MESSAGE_TYPE_VOICE)){
& & & & & & json = &{\&touser\&: \&&+toUser+&\&,\&msgtype\&: \&voice\&, \&voice\&: {\&media_id\&: \&&+mediaId+&\&}}&;
& & & & //获取access_token
& & & &GetExistAccessToken getExistAccessToken = GetExistAccessToken.getInstance();
& & & &String accessToken = getExistAccessToken.getExistAccessToken();
& & & &//获取请求路径
& & & &String action = &https://api./cgi-bin/message/custom/send?access_token=&+accessT
& & & &try {
& & & & & &connectWeiXinInterface(action,json);
& & & &} catch (Exception e) {
& & & & & &e.printStackTrace();
& & &* &发送图文给所有的用户
& & &* @param openId 用户的id
& & public &void sendNewsToUser(String openId){
& & & & MediaUtil mediaUtil = MediaUtil.getInstance();
& & & & ArrayList&Object& articles = new ArrayList&Object&();
& & & &Article a = new Article();
& & & &articles.add(a);
& & & &String str = JsonUtil.getJsonStrFromList(articles);
& & & & String json = &{\&touser\&:\&&+openId+&\&,\&msgtype\&:\&news\&,\&news\&:& +
& & & & & & & & &{\&articles\&:& +str +&}&+&}&;
& & & & json = json.replace(&picUrl&, &picurl&);
& & & & System.out.println(json);
& & & & //获取access_token
& & & &String access_token = mediaUtil.getAccess_token();
& & & &//获取请求路径
& & & &String action = &https://api./cgi-bin/message/custom/send?access_token=&+access_
& & & &try {
& & & & & &connectWeiXinInterface(action,json);
& & & &} catch (Exception e) {
& & & & & &e.printStackTrace();
& & &* 连接请求微信后台接口
& & &* @param action 接口url
& & &* @param json &请求接口传送的json字符串
& & public &void connectWeiXinInterface(String action,String json){
& & & & URL
& & & &try {
& & & & & &url = new URL(action);
& & & & & &HttpURLConnection http = (HttpURLConnection) url.openConnection();
& & & & & &http.setRequestMethod(&POST&);
& & & & & &http.setRequestProperty(&Content-Type&,
& & & & & & & & & &&application/x-www-form-urlencoded&);
& & & & & &http.setDoOutput(true);
& & & & & &http.setDoInput(true);
& & & & & &System.setProperty(&sun.net.client.defaultConnectTimeout&, &30000&);// 连接超时30秒
& & & & & &System.setProperty(&sun.net.client.defaultReadTimeout&, &30000&); // 读取超时30秒
& & & & & &http.connect();
& & & & & &OutputStream os = http.getOutputStream();
& & & & & &os.write(json.getBytes(&UTF-8&));// 传入参数
& & & & & &InputStream is = http.getInputStream();
& & & & & &int size = is.available();
& & & & & &byte[] jsonBytes = new byte[size];
& & & & & &is.read(jsonBytes);
& & & & & &String result = new String(jsonBytes, &UTF-8&);
& & & & & &System.out.println(&请求返回结果:&+result);
& & & & & &os.flush();
& & & & & &os.close();
& & & &} catch (Exception e) {
& & & & & &e.printStackTrace();
转载地址:/article/b907e627b1e4bb46e7891cf0.html
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:651532次
积分:8104
积分:8104
排名:第1381名
原创:123篇
转载:577篇
评论:66条
(7)(71)(38)(24)(25)(19)(19)(11)(7)(1)(2)(10)(18)(21)(22)(80)(26)(28)(13)(16)(14)(42)(21)(7)(4)(18)(9)(12)(5)(12)(38)(4)(30)(28)

我要回帖

更多关于 微信主动发送消息接口 的文章

 

随机推荐