|
@@ -882,3 +882,118 @@ if (!function_exists('attr_format')) {
|
|
|
return [$data, $res];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+if (!function_exists('not_empty_check')) {
|
|
|
+
|
|
|
+ * 非空验证
|
|
|
+ * @param $param
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ function not_empty_check($param)
|
|
|
+ {
|
|
|
+ if (is_array($param)) {
|
|
|
+ return !(count($param) <= 0);
|
|
|
+ } else {
|
|
|
+ if ($param == '') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($param == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (!function_exists('mobile_check')) {
|
|
|
+
|
|
|
+ * 电话验证
|
|
|
+ * @param $param
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ function mobile_check($param)
|
|
|
+ {
|
|
|
+ if (!preg_match("/^1[3456789]\d{9}$/", $param)) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (!function_exists('do_request')) {
|
|
|
+
|
|
|
+ * CURL 请求接口
|
|
|
+ * @param string $url 请求地址
|
|
|
+ * @param array $data 请求参数
|
|
|
+ * @param array $header 请求头
|
|
|
+ * @param bool $post true:post请求 false:get请求
|
|
|
+ * @param bool $json post请求时 请求数据打包方式是否为json
|
|
|
+ * @param int $format 数据打包为json格式时打包的格式值 来自json_encode
|
|
|
+ * @param bool $form post请求时 请求数据是否为表单 同时为false时为http提交 优先级高于json
|
|
|
+ * @return bool|false|string
|
|
|
+ */
|
|
|
+ function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
|
|
|
+ {
|
|
|
+ $curl = curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ if ($post) {
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ if (!$json && !$form) {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
|
+ } else if ($json && !$form) {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
|
|
|
+ } else {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ if ($header) {
|
|
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ }
|
|
|
+ $result = curl_exec($curl);
|
|
|
+ if (curl_errno($curl)) {
|
|
|
+ return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
|
|
|
+ }
|
|
|
+ curl_close($curl);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (!function_exists('get_distance')) {
|
|
|
+ function get_distance($lat1, $lng1, $lat2, $lng2)
|
|
|
+ {
|
|
|
+ $EARTH_RADIUS = 6378137;
|
|
|
+
|
|
|
+ $radLat1 = rad($lat1);
|
|
|
+ $radLat2 = rad($lat2);
|
|
|
+ $a = $radLat1 - $radLat2;
|
|
|
+ $b = rad($lng1) - rad($lng2);
|
|
|
+ $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
|
|
|
+ $s = $s * $EARTH_RADIUS;
|
|
|
+ $s = round($s * 10000) / 10000;
|
|
|
+ return $s;
|
|
|
+ }
|
|
|
+}
|
|
|
+if (!function_exists('rad')) {
|
|
|
+ function rad($d)
|
|
|
+ {
|
|
|
+ return $d * M_PI / 180.0;
|
|
|
+ }
|
|
|
+}
|
|
|
+if (!function_exists('file_debug')) {
|
|
|
+
|
|
|
+ * @param $file
|
|
|
+ * @param $title
|
|
|
+ * @param $data
|
|
|
+ * @param int $step
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ function file_debug($file, $title, $data, $step = 0)
|
|
|
+ {
|
|
|
+ file_put_contents($file, "【" . date('Y-m-d H:i:s') . "】{$title}:" . ($step > 0 ? ('(step' . $step . ')') : '') . json_encode($data) . PHP_EOL, FILE_APPEND);
|
|
|
+ }
|
|
|
+}
|