123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace mtopcard;
- class open_query
- {
- private const OPENAPI_URL = 'https://openapi.xyzshops.cn/api.php/CardInfo/query';
- private const APPID = 'ea97586b4aa0c141e4456912f3325f7f';
- private const SECURE = '92c51d28e3405c923decf1b333cec3ce';
- public function validate($card_no)
- {
- $params = ['cardno' => $card_no, 'appid' => self::APPID];
- $params['sign'] = $this->sign($params);
- $resp = http_request(self::OPENAPI_URL,$params);
- if(empty($resp)) {
- return [false,[]];
- }
- $resp = json_decode($resp, true);
- if ($resp['code'] == 200) {
- $result = $resp['data'];
- return [true, $result];
- } else {
- return [false, []];
- }
- }
- private function sign($input)
- {
- $body = $this->body($input);
- $body .= "&key=" . self::SECURE;
- return md5($body);
- }
- private function check_empty($value)
- {
- if (!isset($value))
- return true;
- if ($value === null)
- return true;
- if (trim($value) === "")
- return true;
- return false;
- }
- private function body($params)
- {
- ksort($params);
- $body = "";
- $i = 0;
- foreach ($params as $k => $v)
- {
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
- {
- if ($i == 0) {
- $body .= "$k" . "=" . urlencode($v);
- } else {
- $body .= "&" . "$k" . "=" . urlencode($v);
- }
- $i++;
- }
- }
- return $body;
- }
- }
|