token=$token; $this->tem_type=$tem_type; $this->parameter=$data; } //选择模板 private function create_tem(){ switch($this->tem_type){ case 1: $this->template_id='oSGXMc3RxDr92mPBYV80Z7yBp0LZ3ulMgY4sdaNn0Sk'; $result= $this->test_template(); break; } return $result; } //充值模板内容 private function test_template(){ //写模板内容 return json_encode(array( 'touser'=>$this->parameter['openId'], 'template_id'=>$this->template_id, 'url'=> $this->parameter['url'], 'topcolor'=>'#000000', 'data'=>array( 'name'=>array('value'=>$this->parameter['name'],'color'=>'#000000') ) ) ); } //发送模板消息 public function send(){ $this->url=$this->url.$this->token; $http = wx_http::factory($this->url, wx_http::TYPE_CURL); $json = $http->post($this->url, $this->create_tem(), array( 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)', 'Content-Type: application/json; charset=utf-8', 'Content-Length: '. strlen($this->create_tem()) )); $result =json_decode($json,true); if(!empty($result) && $result['errcode']==0 and $result['errmsg']=='ok'){ return true; }else{ return false; } } }