Commit 2f37a45cf62706bbf85dfa9fd670810cc774231d
1 parent
d8f0de6c
Exists in
master
防伪标签接口调用调整。
Showing
2 changed files
with
70 additions
and
9 deletions
Show diff stats
app-wx/controllers/TestController.php
... | ... | @@ -3,9 +3,11 @@ |
3 | 3 | namespace app\wx\controllers; |
4 | 4 | |
5 | 5 | use Yii; |
6 | +use common\helpers\CheckActiveHelper; | |
6 | 7 | use domain\system\message\SmsMessage; |
8 | +use yii\web\Controller; | |
7 | 9 | |
8 | -class TestController extends AppController | |
10 | +class TestController extends Controller | |
9 | 11 | { |
10 | 12 | public $layout = 'test'; |
11 | 13 | |
... | ... | @@ -22,7 +24,10 @@ class TestController extends AppController |
22 | 24 | } |
23 | 25 | public function actionTestMsg() |
24 | 26 | { |
25 | - $sms = new SmsMessage(); | |
26 | - $sms->sendGetCode("15999944931", "333333"); | |
27 | + //$sms = new SmsMessage(); | |
28 | + //$sms->sendGetCode("15999944931", "333333"); | |
29 | + $fileName = "IMG_iGavHy6K1TIqPba6888879_1577200522.jpg"; | |
30 | + $fileFullName = "https://smart-anti-fake.oss-cn-hongkong.aliyuncs.com/check/20191224/8/IMG_iGavHy6K1TIqPba6888879_1577200522.jpg"; | |
31 | + var_dump(CheckActiveHelper::checkAppQrv($fileFullName, $fileName, "")); | |
27 | 32 | } |
28 | 33 | } |
29 | 34 | \ No newline at end of file | ... | ... |
common/helpers/CheckActiveHelper.php
... | ... | @@ -17,21 +17,24 @@ use function base64_encode; |
17 | 17 | |
18 | 18 | class CheckActiveHelper |
19 | 19 | { |
20 | - const CHECK_URL = 'http://zhoundlee.com/app_qrv'; | |
20 | + const CHECK_URL = 'http://check1.bosch-smartlife.com/app_qrv'; | |
21 | 21 | |
22 | - const ACTIVE_URL = 'http://zhoundlee.com/app_activate'; | |
22 | + const ACTIVE_URL = 'http://check1.bosch-smartlife.com/app_activate'; | |
23 | + | |
24 | + const APP_CHECK = 'http://check1.bosch-smartlife.com/app_check'; | |
23 | 25 | |
24 | 26 | /** |
25 | 27 | * 调用智纹保校验接口 |
26 | 28 | * @param $img 图片内容 file 是 用户上传的图片,文件类型(二进制图片数据) |
27 | 29 | * @param $fileName 图片名称 string 是 用户上传的图片原始名字 |
30 | + * @param $token string 是 访问令牌 | |
28 | 31 | * 格式: IMG_防伪标签uuid_时间戳.jpg 注意: 1) 中间两个下划线 _ 不可省略 2) 微信扫码出来的uuid参数中的版本号部分去掉@v1.0 |
29 | 32 | * @return bool|string "" |
30 | 33 | * content object 内容 |
31 | 34 | * status string 状态码【待定】(authentic:正品 fake:假货 其他状态码:请闵总帮忙补充) |
32 | 35 | * imgUrl file 返回的图片状态 备注:请返回完整的URL路径,例如:http://check1.bosch-smartlife.com/images/success.png |
33 | 36 | */ |
34 | - public static function checkAppQrv($imageFullPath, $fileName) | |
37 | + public static function checkAppQrv($imageFullPath, $fileName, $token) | |
35 | 38 | { |
36 | 39 | try { |
37 | 40 | $curl = curl_init(); |
... | ... | @@ -43,7 +46,8 @@ class CheckActiveHelper |
43 | 46 | // 设置post数据 |
44 | 47 | $post_data = array( |
45 | 48 | "img" => $image, |
46 | - "fileName" => $fileName | |
49 | + "fileName" => $fileName, | |
50 | + "token" => $token | |
47 | 51 | ); |
48 | 52 | // 如果是https协议 |
49 | 53 | if (stripos(self::CHECK_URL, "https://") !== FALSE) { |
... | ... | @@ -79,10 +83,11 @@ class CheckActiveHelper |
79 | 83 | /** |
80 | 84 | * 防伪标签的激活 |
81 | 85 | * @param $uuid string 是 防伪标签uuid |
86 | + * @param $token string 是 访问令牌 | |
82 | 87 | * @return mixed|string {"status": "success"} |
83 | 88 | * 状态码:success:激活成功 fail:激活失败,无效标签 activated:已激活过 |
84 | 89 | */ |
85 | - public static function getAppActivate($uuid) | |
90 | + public static function getAppActivate($uuid, $token) | |
86 | 91 | { |
87 | 92 | try { |
88 | 93 | $curl = curl_init(); |
... | ... | @@ -92,7 +97,58 @@ class CheckActiveHelper |
92 | 97 | ));*/ |
93 | 98 | //设置post数据 |
94 | 99 | $post_data = array( |
95 | - "uuid" => $uuid | |
100 | + "uuid" => $uuid, | |
101 | + "token" => $token | |
102 | + );; | |
103 | + //如果是https协议 | |
104 | + if (stripos(self::ACTIVE_URL, "https://") !== FALSE) { | |
105 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | |
106 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | |
107 | + curl_setopt($curl, CURLOPT_SSLVERSION, 1); | |
108 | + } | |
109 | + //通过POST方式提交 | |
110 | + curl_setopt($curl, CURLOPT_POST, true); | |
111 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); | |
112 | + | |
113 | + //超时时间 | |
114 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); | |
115 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); | |
116 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
117 | + //返回内容 | |
118 | + $callbcak = curl_exec($curl); | |
119 | + //http状态码 | |
120 | + $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); | |
121 | + //状态处理 | |
122 | + if (in_array($httpCode, array(400, 403))) | |
123 | + return ""; | |
124 | + //关闭,释放资源 | |
125 | + curl_close($curl); | |
126 | + //返回内容JSON_DECODE | |
127 | + return json_decode($callbcak, true); | |
128 | + } catch (Exception $e) { | |
129 | + return false; | |
130 | + } | |
131 | + } | |
132 | + | |
133 | + /** | |
134 | + * 校验防伪标签编号 | |
135 | + * @param $uuid string 是 防伪标签uuid | |
136 | + * @param $token string 是 访问令牌 | |
137 | + * @return mixed|string {"status": "success"} | |
138 | + * 状态码:success:激活成功 fail:激活失败,无效标签 activated:已激活过 | |
139 | + */ | |
140 | + public static function getAppCheck($uuid, $token) | |
141 | + { | |
142 | + try { | |
143 | + $curl = curl_init(); | |
144 | + curl_setopt($curl, CURLOPT_URL, self::APP_CHECK); | |
145 | + /*curl_setopt($curl, CURLOPT_HTTPHEADER, array ( | |
146 | + 'Authorization:APPCODE '.self::APPCODE_IMAGE | |
147 | + ));*/ | |
148 | + //设置post数据 | |
149 | + $post_data = array( | |
150 | + "uuid" => $uuid, | |
151 | + "token" => $token | |
96 | 152 | );; |
97 | 153 | //如果是https协议 |
98 | 154 | if (stripos(self::ACTIVE_URL, "https://") !== FALSE) { | ... | ... |