美文网首页
PHP发送post请求的步骤

PHP发送post请求的步骤

作者: 蜗牛呀呀呀呀呀 | 来源:发表于2019-05-02 17:26 被阅读0次
public function doWebChubi(){
        global $_W,$_GPC;
        $jiqibianhao=$_GPC['jiqibianhao'];
        $result=pdo_get('ewei_shop_key',array('id'=>1));
        $url="https://api.weimaqi.net/weimaqi_device_api/Services.aspx";
        $danhao = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        $action='Payout';
        $coin_count=0;
        $stringA="action=".$action."&api_pw=".$result['api_pw']."&coin_count=".$coin_count."&device_name=".$jiqibianhao."&mch_id=".$result['mch_id']."&order_id=".$danhao;
    $stringSignTemp=$stringA."&key=".$result['key'];
        $sign=strtoupper(MD5($stringSignTemp));     
        $post=array(
            'action'=>'Payout',
            'api_pw' => $result['api_pw'],
            'coin_count'=>$coin_count,
            'device_name'=>$jiqibianhao,
            'mch_id'=>'50503',          
            'order_id'=>$danhao,            
            'sign'=>$sign,
        );
          $post = json_encode($post);     
       //1.初始化curl句柄
        $ch = curl_init();       
        //2.设置curl
        //设置访问url
        curl_setopt($ch, CURLOPT_URL, $url);         
        //捕获内容,但不输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);       
        //模拟发送POST请求
        curl_setopt($ch, CURLOPT_POST, 1);          
        //发送POST请求时传递的参数
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);          
        //设置头信息
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(  
            'Content-Type: application/json; charset=utf-8',  
            'Content-Length: ' . strlen($post))  
        );  
        //3.执行curl_exec($ch)
        $return_content = curl_exec($ch);          //如果获取失败返回错误信息
        if($return_content === FALSE){ 
            $return_content = curl_errno($ch);
        }
        //4.关闭curl
        curl_close($ch);
        return $return_content;
       $machine= json_decode($return_content,true);//转化为数字在html中使用

    }

相关文章

网友评论

      本文标题:PHP发送post请求的步骤

      本文链接:https://www.haomeiwen.com/subject/gywxlqtx.html