微信查詢四六級成績代碼

使用curl請求99宿舍接口查詢,再調用微信客服接口返回信息。html

 

    //四六級查詢,方倍工做室出品
    public function cet_query(){
        $openid = I("post.openid");
        if ($_SERVER['HTTP_HOST'] != "www.fangbei.org"){
            $arr = array('info' => "非法調用,請關注方倍工做室官方帳號進入查詢");
        }else{
            $name = I("post.name");
            $number = I("post.number");
            $name_gb2312 = urlencode(mb_convert_encoding($name, 'gb2312', 'utf-8'));
            $data = "id=".$number."&name=".$name_gb2312;

            $url = "https://cet.99sushe.com/getscore".$number;
            $headers = array(
            "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1",
            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Accept-Language: en-us,en;q=0.5",
            "Referer: http://cet.99sushe.com/"
            );
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,false);
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            $output = curl_exec($curl);
            curl_close($curl);

            $result = iconv("GBK", "UTF-8//IGNORE", $output);
            $score = explode(",",$result);
            Vendor('Weixin.basicclass');
            $weixin = new \weixin();
            if (count($score)>4){
                $arr = array(
                    'info' => "姓名:".$score[6]."\\n學校:".$score[5]."\\n總分:".$score[4]
                );

                $data = array();
                $type = substr($number,9,1);
                $typestr = array("1"=>"四級","2"=>"六級");
                $data[] = array("title"=>"CET成績單", "description"=>"", "picurl"=>"", "url" =>"");
                $data[] = array("title"=>"考生姓名:".$score[6]."\n學校名稱:".$score[5], "description"=>"", "picurl"=>"", "url" =>"");
                $data[] = array("title"=>"考試類別:".$typestr[$type]."\n准考證號:".$number, "description"=>"", "picurl"=>$orderArr["product_img"], "url" =>"");
                $data[] = array("title"=>"聽力部分:".$score[1]."\n閱讀部分:".$score[2]."\n寫做翻譯:".$score[3]."\n成績總分:".$score[4], "description"=>"", 
                "picurl"=>($score[4] > 425)?"https://www.cnblogs.com/txw1958/ok.jpg":"https://www.cnblogs.com/txw1958/error.jpg", "url" =>"");
                $data[] = array("title"=>"技術支持 方倍工做室", "description"=>"", 
                "picurl"=>"", "url" =>"https://www.cnblogs.com/txw1958/");
                $result2 = $weixin->send_custom_message($openid, "news", $data);
            }else{
                $arr = array(
                    'info' => "姓名:".$score[6]."\\n學校:".$score[5]."\\n總分:".$score[4]
                );
                $result2 = $weixin->send_custom_message($openid, "text", "Error\n".$name."\n".$number);
            }
        }


        echo json_encode($arr);
    }
相關文章
相關標籤/搜索