Wechat Template Message Mass Sending Breaks through 4 Limits

http://blog.csdn.net/sflsgfs/article/details/50905187

 

WeChat account is divided into service account and subscription account (also used internally by enterprise account), service account is like QQ, the other party sends you a message, you can see it immediately, subscription account is like an email, you must open the other party’s subscription account to see it instant information. Therefore, the service account is more like an ordinary WeChat friend who can communicate online. However, in order to control the advertising effect of WeChat, the service account can only send messages 4 times a month, while the subscription account can send messages once a day. Although the official account can also be sent by programming with the advanced group messaging interface, what is even more powerful is that the WeChat client limits each user to receive only 4 messages from the official account. So if you only send it by programming, more than 4 times, the user will not know that there is this message at all, and the WeChat server will block it for you. Fortunately, WeChat has left an opening for enterprise services. Graphical messages are not allowed to be sent, but simple text messages can be sent, breaking through the restrictions of public accounts, and the method of sending one message per day is just this interface. Wechat monitors this interface, with a daily limit of 10,000 calls. We only have a few thousand followers, which is enough.

 

<?php  
  
 $appid = "wx";  
 $appsecret = "0b97ad645797ee2";  
 $times= date('y年m月d日 H:i:s',time());  
echo $times."</br>";  
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;//取得token  
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$output = curl_exec($ch);  
curl_close($ch);  
$jsoninfo = json_decode($output, true);  
$access_token = $jsoninfo["access_token"];  
// echo $access_token."</br>";  
  
$begin=0;  
if($begin>=10000)  
{$url= "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token."&next_openid=".$_GET['next_openid'];}  
else{$url= "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token; }  
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
$output = curl_exec($ch);  
curl_close($ch);  
$array = json_decode($output, true);  
echo $array["count"]."</br>";  
// foreach ($array["data"]["openid"] as $key=>&$value) {//Get the user's unique ID  
//     echo ($key)."->".$value."</br>" ;  
// } // Group comments  
  
$times= date('y年m月d日 H:i:s',time());  
$template = array('touser' =>"oC282t60QEDt0El-hcVOShgzgTmQ",//&$value, // //  
    'template_id' => "gJ_qahsRIMxRtxeWtKuhChzfA6w8HHdZE2xa7_XQ5u8",  
//     'url' =>"http://eqxiu.com/s/7pWq",  
    'url' => "http://mp.weixin.qq.com/",  
    'topcolor' => "#7B68EE",  
    'data' => array('first'    => array('value' => urlencode("新闻标题:"),  
        'color' => "#743A3A",  
    ),  
        'keyword1' => array('value' => urlencode("XXXXXX"),  
            'color' => "#FF0000",  
        ),  
        'keyword2' => array('value' => urlencode("All care about XXX"),  
            'color' => "#C4C400",  
        ),  
        'keyword3'     => array('value' => urlencode($times),  
            'color' => "#0000FF",  
        ),  
        'keyword4' => array('value' => urlencode("Work advanced collective"),  
            'color' => "#FF0000",  
        ),  
        'remark' => array('value' => urlencode("\\nHello. Click to view "details"!"),  
            'color' => "#008000",  
        ),  
  
    )  
);  
// var_dump($template)."</br>";  
// echo urldecode(json_encode($template))."</br>";  
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;  
$result = https_request($url, urldecode(json_encode($template)));//"";//Group command  
// var_dump($result)."</br>";  
// } //Group send close  
function https_request($url,$data = null){  
    $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);  
    $output = curl_exec($curl);  
    curl_close($curl);  
//     echo "</br>";  
//     echo $output;  
    return $output;  
}  

 Save it as a php file and set it up

 

$appid = "wx";
$appsecret = "0b97ad645797ee2"; Change a
few comments and you can use it, it is best to send it to your own account to test it

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326293276&siteId=291194637