123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\common\library;
- use think\Controller;
- header('Content-type:text/html;charset=utf-8');
- class Jiyan extends Controller
- {
- public static function jy($lot_number,$captcha_output,$pass_token,$gen_time,$type)
- {
-
- error_reporting(0);
-
-
- switch ($type){
- case 1:
- $captcha_id = "46c329019f54e6d6e2171bc93da4fc57";
- $captcha_key = "fcea1180bef1b1a84d3acb6338a4200c";
- break;
- case 2:
- $captcha_id = "f79240154d3834df7b73d5514d555fff";
- $captcha_key = "97ad4e9039d04bc21222fc504152708e";
- break;
- }
- $api_server = "http://gcaptcha4.geetest.com";
-
- $sign_token = hash_hmac('sha256', $lot_number, $captcha_key);
- $query = array(
- "lot_number" => $lot_number,
- "captcha_output" => $captcha_output,
- "pass_token" => $pass_token,
- "gen_time" => $gen_time,
- "sign_token" => $sign_token
- );
- $url = sprintf($api_server . "/validate" . "?captcha_id=%s", $captcha_id);
- $res = self::post_request($url,$query);
- $obj = json_decode($res,true);
- return $obj;
- }
-
- public static function post_request($url, $postdata) {
- $data = http_build_query($postdata);
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => "Content-type: application/x-www-form-urlencoded",
- 'content' => $data,
- 'timeout' => 5
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- if($http_response_header[0] != 'HTTP/1.1 200 OK'){
- $result = array(
- "result" => "success",
- "reason" => "request geetest api fail"
- );
- return json_encode($result);
- }else{
- return $result;
- }
- }
- }
|