zoukankan      html  css  js  c++  java
  • CURL,PHP请求k780接口

    <?php
    //curl请求k780接口
    header("Content-Type:text/html;charset=UTF-8");
    $url='http://api.k780.com:88/?app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json';
    $ch = curl_init();//初始化curl
    curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1);    //post提交方式
    //    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost)
    $data = curl_exec($ch);//运行curl
    curl_close($ch);
    print_r($data);


    die;
    //php请求k780接口
    function nowapi_call($a_parm){
        if(!is_array($a_parm)){
            return false;
        }
        //combinations
        $a_parm['format']=empty($a_parm['format'])?'json':$a_parm['format'];
        $apiurl=empty($a_parm['apiurl'])?'http://api.k780.com:88/?':$a_parm['apiurl'].'/?';
        unset($a_parm['apiurl']);
        foreach($a_parm as $k=>$v){
            $apiurl.=$k.'='.$v.'&';
        }
        $apiurl=substr($apiurl,0,-1);
        if(!$callapi=file_get_contents($apiurl)){
            return false;
        }
        //format
        if($a_parm['format']=='base64'){
            $a_cdata=unserialize(base64_decode($callapi));
        }elseif($a_parm['format']=='json'){
            if(!$a_cdata=json_decode($callapi,true)){
                return false;
            }
        }else{
            return false;
        }
        //array
        if($a_cdata['success']!='1'){
            echo $a_cdata['msgid'].' '.$a_cdata['msg'];
            return false;
        }
        return $a_cdata['result'];
    }

    $nowapi_parm['app']='weather.future';
    $nowapi_parm['weaid']='1';
    $nowapi_parm['appkey']='22084';
    $nowapi_parm['sign']='24a673cd5d57baad69e5e61fa21849f7';
    $nowapi_parm['format']='json';
    $result=nowapi_call($nowapi_parm);
    var_dump($result);
    print_r($result);

  • 相关阅读:
    直接插入排序
    排序概述
    因为现在这个水平还用不到树和图,所有之后放弃树和图的学习,直接进入排序的学习,现在学到排序树的删除部分,还没学完删除
    检索树
    二叉树的构造
    dedecms 忘记后台密码
    php配置伪静态的方法
    thinkPHP 中去除URL中的index.php
    thinkphp 验证码的使用
    php MySQL数据库操作类源代码
  • 原文地址:https://www.cnblogs.com/taikongliu/p/6736888.html
Copyright © 2011-2022 走看看