security.msgSecCheck返回的都是ok?
发布于 4 年前 作者 xiuyingren 6843 次浏览 来自 问答

测试的文案就是用文档上提供的那两句

特3456书yuuo莞6543李zxcz蒜7782法fgnv级
完2347全dfji试3726测asad感3847知qwez到

服务器代码用PHP写

//post请求代码
static
function curlPOST( $url = '', $data )
{
    $headers = array("Content-type: application/json;charset=UTF-8","Accept: application/json","Cache-Control: no-cache", "Pragma: no-cache");
    $data=json_encode($data);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
    $output = curl_exec($curl);
    curl_close($curl);
    return json_decode($output,true);
}
// 调用security.msgSecCheck
static
function msgSecCheck( $content )
{
    $access_token = Wechat::getAccessToken();
    $url          = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' . $access_token;
//        dump(mb_detect_encoding($content, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5')));
    $data = Wechat::curlPOST( $url, [ 'content' => $content ] );
    dump($data);

    if($data['errmsg'] == 'ok' and $data['errcode'] === 0) return true;
    return false;
}
1 回复

编码问题,你试试拼音xidada

回到顶部