當前位置:名人名言大全網 - 短信平臺 - php如何編寫壹個微信公眾平臺的消息推送?

php如何編寫壹個微信公眾平臺的消息推送?

給妳個代碼樣例?不可以直接復制使用

/**

*?發送模板消息

*?@param?$tmpId?模板ID

*?@param?$openId?用戶openID

*?@param?$param?模板參數

*?@param?$url

*?@return?mixed

*?@author?fjlhuman

*/

public?function?sendTmpMessage($tmpId,$openId,$param,$url){

$postUrl?=?"/cgi-bin/message/template/send?access_token=".$this->accessToken;

$arrData['touser']=$openId;

$arrData['template_id']=$tmpId;//'6OT8DDNF-CbiadTsbEKKSCZVHe_9hnhxOBT7EvURNcE';

$arrData['url']=$url;

$arrData['data']=$param;

$json=json_encode($arrData);

$result?=?Curl::post($postUrl,?$json);

$result=json_decode($result,?true);

$rData['isTure']=false;

$rData['msg']="";

if($result['errcode']==0){

$rData['isTure']=true;

$rData['msg']="發送成功";

}else{

$rData['msg']=$result['errcode'];

}

return?$rData;

}

詳情請參考?微信公眾平臺技術文檔->模板消息接口 ?