javascript - nodejs 微信群发消息content 报empty content
大家讲道理
大家讲道理 2017-04-11 11:16:31
0
3
1256

T T 求大神。。
背景:

1、微信测试号
2、微信群发接口,文本消息

3、英文数字能够发送成功,但是发送中文消息(一个字可以T T,多于一个字的中文就报错)报错
errcode 44004 errmsg empty content hint WxrcNA0859age8


代码:

/**
 * Created by hh on 2016/6/28.
 * 消息推送
 */
var http = require("http");
var https = require("https");
var url = require("url");
var request = require("request");
var needle = require("needle");
var access_token;
http.createServer(function(req, response) {
    response.writeHead(200, {"Content-Type": "text/plain" ,"Access-Control-Allow-Origin":"*"});

    getServise("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET",
        function(data){
            access_token = JSON.parse(data).access_token;
            var txt = "00我想我想我想吃东西";
            postCode( {
                "touser":["oi7M0wpwce27aR-8vioIg1zMjS5I","oi7M0wpvv57bKIqqJUuR3JBVb_eA"],
                "msgtype": "text",
                "text": { "content": txt}
            },access_token);

        });
    //response.end();

}).listen(8008);

//get方法
function getServise(url,callback){
    var req = https.request(url, function (res) {
        //console.log('STATUS: ' + res.statusCode);
        //console.log('HEADERS: ' + JSON.stringify(res.headers));
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('BODY: ' + chunk);
            callback(chunk);
        });
    });

    req.on('error', function (e) {
        console.log('problem with request: ' + e.message);
    });

    req.end();
}
//post方法
function postCode(data,access_token) {
    // Build the post string from an object
    var post_data = JSON.stringify(data);
    // An object of options to indicate where to post to
    var post_options = {
        host: 'api.weixin.qq.com',
        port: '80',
        path: "/cgi-bin/message/mass/send?access_token="+access_token,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
            'Content-Length': post_data.length
        }
    };

    // Set up the request
    var post_req = http.request(post_options, function(res) {
        console.log(typeof post_data);
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('Response: ' + chunk);
        });
        res.on('error', function (e) {
            console.log('eeeee: ' + e);
        });
    });


    // post the data
    post_req.write(post_data);
    post_req.end();
}
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(3)
phpcn_u99644

请问你这个问题解决了吗,我也遇到了

迷茫

我就友情提示一下你的appid干嘛放出来

大家讲道理

碰到过 类似的问题 但是发送中文消息(一个字可以T T,多于一个字的中文就报错)报错
处理一下编码问题吧

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage