php使用post功能,调用微信推送服务

因业务需要,在提交工单后,需要第一时间通知管理员,故有了微信提醒需求。

微信推送服务接口因开发时间原因,不在自行搭建。这里我选择了 wxpusher 接口,非常方便。

文档在此:

http://wxpusher.zjiecode.com/docs/#/

以下为调用代码

        $geturl="http://wxpusher.zjiecode.com/api/fun/wxuser";//获取订阅者的api
        $pushapi="http://wxpusher.zjiecode.com/api/send/message";//推送渠道api
        //$appToken="apitoken_xxxx";//:应用api

        //先获取该应用已定阅的uid
        $s = file_get_contents($geturl."?appToken=".$appToken);
        $returnmsg = json_decode($s, true);
        $useruidarray=array();
        if($returnmsg['success']){
            foreach ($returnmsg['data']['records'] as $kbb  ){
                array_push($useruidarray,  $kbb['uid']); 
            } 
    
            $dataarry =json_encode(array("appToken"=>$appToken,
                        "content"=>$pushmsg,
                        "contentType"=>1,
                        "uids"=>$useruidarray,
                        //"topicIds"=>array(158)
                        //"url"=>"http://wxpusher.zjiecode.com" 
                    ));
            $ddd=  http_post_json($pushapi,$dataarry);
            $tem = json_decode($ddd[1], true);
            return $tem["success"];
        }
        else{
            return false;
        }    

以上

猜你喜欢

转载自www.cnblogs.com/Lbox/p/12586959.html