1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * 添加自定义辅助函数
- */
- if ( ! function_exists('config_path'))
- {
- /**
- * Get the configuration path.
- *
- * @param string $path
- * @return string
- */
- function config_path($path = '')
- {
- return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
- }
- }
- /**
- * @param $url 地址
- * @param $param 参数
- * @param bool $isCheck 是否检查返回结果
- * @param string $method 请求方式
- * @return array|mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- function http($url, $param, $isCheck = true, $method = 'post')
- {
- try {
- $client = new \GuzzleHttp\Client();
- $response = $client->request($method, $url, $param);
- $result = json_decode($response->getBody()->getContents(), true);
- if ($isCheck == true) {
- if ($result['code'] == 0) {
- return $result['data'];
- } else {
- return [];
- }
- } else {
- return $result;
- }
- } catch (\Exception $exception) {
- return [];
- }
- }
- function generateSign(array $params, $secret_key)
- {
- unset($params['sign']);
- // 将删除参数组中所有等值为FALSE的参数(包括:NULL, 空字符串,0, false)
- $params = array_filter($params);
- // 按照键名对参数数组进行升序排序
- ksort($params);
- // 给参数数组追加密钥,键名为 key, 值为签名配置中配置的 secret_key 的值
- $params['chxq_key'] = $secret_key;
- \Illuminate\Support\Facades\Log::debug($params);
- // 生成 URL-encode 之后的请求字符串
- $str = http_build_query($params);
- $str = urldecode($str);
- \Illuminate\Support\Facades\Log::debug($str);
- //$str = "address=计算机啊手机壳阿看见手机卡&address_type=1&area_id=2&area_name=西安市&city_id=2&city_name=西安市&contact_mobile
- //=18458881890&contact_name=刘德华&province_id=1&province_name=陕西省&uid=0&zipcode=1000000";
- // 将请求字符串使用MD5加密后,再转换成大写,并返回
- return strtoupper(MD5($str));
- }
|