123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Handlers;
- use App\Models\AreaSetting;
- use App\Models\Order;
- use App\Models\Parking;
- use App\Models\User;
- use App\Repositories\ParkingRepository;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class IdCardHandler
- {
- const URL = 'https://route.showapi.com/1072-1?';
- const AppKey = '344488';
- const AppSecret = '9426aa0ea2624a3ba5c6f5d1e1f030b5';
- public static function main($idCard, $trueName)
- {
- $paramArr = array(
- 'showapi_appid' => config('bike.cardId_auth.AppKey'),
- 'idcard' => $idCard,
- 'name' => $trueName
- );
- $url = config('bike.cardId_auth.url') . self::createParam($paramArr);
- Log::error($url);
- $data = self::curl_get_contents($url);
- Log::info($data);
- $status = $data['showapi_res_body'];
- return [
- 'code' => $status['code'],
- 'msg' => $status['msg'],
- ];
- }
- //创建参数(包括签名的处理)
- private static function createParam($paramArr)
- {
- $paraStr = "";
- $signStr = "";
- ksort($paramArr);
- foreach ($paramArr as $key => $val) {
- if ($key != '' && $val != '') {
- $signStr .= $key . $val;
- $paraStr .= $key . '=' . urlencode($val) . '&';
- }
- }
- $signStr .= config('bike.cardId_auth.AppSecret');//排好序的参数加上secret,进行md5
- $sign = strtolower(md5($signStr));
- $paraStr .= 'showapi_sign=' . $sign;//将md5后的值作为参数,便于服务器的效验
- return $paraStr;
- }
- public static function curl_get_contents($url)
- {
- $curl = curl_init();
- //设置抓取的url
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回,而不是直接输出
- $data = curl_exec($curl); //执行命令
- curl_close($curl); //关闭URL请求
- return js2php($data);
- }
- }
|