yii中通过HTTP post接收


创建一个CURL.php的文件然后引用
1
<?php 2 namespace frontend\models; 3 class Curl 4 { 5 public function getCurl($url,$type='get',$data,$https='true') 6 { 7 $ch = curl_init($url); 8 curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 9 if($type=='post') 10 { 11 curl_setopt($ch,CURLOPT_POST,1); 12 curl_setopt($ch,CURLOPT_POSTFIELDS,$data); 13 } 14 if($https=='false') 15 { 16 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); 17 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); 18 } 19 $data=curl_exec($ch); 20 curl_close($ch); 21 return $data; 22 } 23 }
创建一个controller
<?php namespace frontend\controllers; use frontend\models\Curl; use yii; use yii\web\Controller; class CatController extends Controller { //权限的添加 public function actionPower() { $data['p_name']=Yii::$app->request->get('p_name'); $url='http://weixin.api.com/index.php/restful/qq';
//实例化curl
$curl = new Curl(); $aa=$curl->getCurl($url,'post',$data); var_dump($aa); } }

 

posted @ 2019-03-12 18:43  PHP小媛  阅读(1183)  评论(0编辑  收藏  举报