123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- <?php
- function route_class()
- {
- return strtolower(str_replace([
- '.',
- '::'
- ], '-', \Illuminate\Support\Facades\Route::currentRouteName()));
- }
- function dda(...$args)
- {
- foreach ($args as &$x) {
- if (method_exists($x, 'toArray')) {
- $x = $x->toArray();
- }
- }
- dd(...$args);
- }
- if (!function_exists('request')) {
-
- function request($key = null, $default = null)
- {
- if (is_null($key)) {
- return app('request');
- }
- if (is_array($key)) {
- return app('request')->only($key);
- }
- $value = app('request')->__get($key);
- return is_null($value) ? value($default) : $value;
- }
- }
- if (!function_exists('wechat_mini_config')) {
-
- function wechat_mini_config($merchant)
- {
- $config = [
- 'app_id' => $merchant['wxapp_app_id'],
- 'secret' => $merchant['wxapp_app_secret'],
-
-
- 'response_type' => 'array',
- 'log' => [
- 'level' => 'debug',
- 'file' => __DIR__ . '/' . $merchant['id'] . '/wechat.log',
- ],
- ];
- return $config;
- }
- }
- if (!function_exists('wechat_pay_config')) {
-
- function wechat_pay_config($merchant)
- {
- $config = [
- 'app_id' => $merchant['wxapp_app_id'],
- 'mch_id' => $merchant['pay_mch_id'],
- 'key' => $merchant['pay_key'],
-
- 'cert_path' => base_path() . '/storage/app/public/merchant/' . $merchant['pay_cert_path'],
- 'key_path' => base_path() . '/storage/app/public/merchant/' . $merchant['pay_key_path'],
- 'notify_url' => config('app.url') . '/api/payments/wechat-notify/' . $merchant['id'],
- ];
- return $config;
- }
- }
- if (!function_exists('alipay_mini_config')) {
-
- function alipay_mini_config($merchant, $notifyUrl = '')
- {
- $options = new Alipay\EasySDK\Kernel\Config();
- $options->protocol = 'https';
- $options->gatewayHost = 'openapi.alipay.com';
- $options->signType = 'RSA2';
- $options->appId = $merchant['alipaymini_appId'];
-
- $options->merchantPrivateKey = $merchant['alipaymini_merchantPrivateKey'];
- $options->alipayCertPath = base_path() . '/database/zhifubao/' . $merchant['alipaymini_alipayCertPath'];
- $options->alipayRootCertPath = base_path() . '/database/zhifubao/' . $merchant['alipaymini_alipayRootCertPath'];
- $options->merchantCertPath = base_path() . '/database/zhifubao/' . $merchant['alipaymini_merchantCertPath'];
- if ($notifyUrl == '') {
-
- $options->notifyUrl = config('app.url') . '/api/alipay_notify/' . $merchant['id'];
- } else {
- $options->notifyUrl = $notifyUrl;
- }
- return Alipay\EasySDK\Kernel\Factory::setOptions($options);
- }
- }
- if (!function_exists('alipay_mini_pay')) {
-
- function alipay_mini_pay($merchant, $desc, $no, $money, $alibuyer)
- {
- $msg = [
- 'code' => 0,
- 'msg' => '',
- 'data' => [],
- ];
- $result = alipay_mini_config($merchant)->payment()->common()->create($desc, $no, $money, $alibuyer);
- $responseChecker = new Alipay\EasySDK\Kernel\Util\ResponseChecker();
- if (!($responseChecker->success($result))) {
- $msg['msg'] = "调用失败,原因:" . $result->msg . "," . $result->subMsg;
- $msg['data'] = $result;
- return $msg;
- }
- return $msg = [
- 'code' => 1,
- 'msg' => '',
- 'data' => $result,
- ];
- }
- }
- if (!function_exists('userAuthinfo')) {
-
- function userAuthinfo($merchant, $user_id, $type = false)
- {
- $msg = [
- 'code' => 0,
- 'msg' => '',
- 'data' => [],
- ];
- if ($type === false) {
- switch (source_type()) {
- case \App\Http\Controllers\Controller::SOURCE_TYPE_WECHAT:
- $type = \App\Models\Auth::TYPE_WEAPP;
- break;
- case \App\Http\Controllers\Controller::SOURCE_TYPE_ALIPAY:
- $type = \App\Models\Auth::TYPE_ALIPAY;
- break;
- }
- }
- if (!in_array($type, [App\Models\Auth::TYPE_WEAPP, App\Models\Auth::TYPE_ALIPAY])) {
- return $msg = [
- 'code' => 0,
- 'msg' => 'type参数不对',
- 'data' => '',
- ];
- }
- $auth = App\Models\Auth::where('merchant_id', $merchant['id'])->where('type', $type)->where('user_id', $user_id)->first();
- if (!$auth) return $msg = [
- 'code' => 0,
- 'msg' => '登录信息不存在',
- 'data' => '',
- ];
- return $msg = [
- 'code' => 1,
- 'data' => $auth,
- ];
- }
- }
- function AlipayYushouquanJiedong($merchant, $order_no, $order_rno)
- {
- $data = [
-
- 'appId' => $merchant['alipaymini_appId'],
- 'rsaPrivateKey' => $merchant['alipaymini_merchantPrivateKey'],
- 'appCertPath' => base_path() . '/storage/app/public/merchant/' . $merchant['alipaymini_merchantCertPath'],
- 'alipayCertPath' => base_path() . '/storage/app/public/merchant/' . $merchant['alipaymini_alipayCertPath'],
- 'rootCertPath' => base_path() . '/storage/app/public/merchant/' . $merchant['alipaymini_alipayRootCertPath'],
-
- 'out_order_no' => $order_no,
- 'out_request_no' => $order_rno,
- ];
- return $data;
- }
- function AlipayYushouquanJiedongQingqiu($data, $auth_no, $out_request_no, $amount)
- {
- $dataarr = [
-
- 'auth_no' => $auth_no,
- 'out_request_no' => $out_request_no,
- 'amount' => $amount,
- 'remark' => '用户骑行押金解冻'
- ];
- $data = array_merge($data, $dataarr);
- return $data;
- }
- if (!function_exists('AlipayMiniOpenSign')) {
- function AlipayMiniOpenSign($merchant, $response_mi)
- {
- $aesKey = $merchant['alipaymini_aesKey'];
- $content = $response_mi;
- $result = openssl_decrypt(base64_decode($content), 'AES-128-CBC', base64_decode($aesKey), OPENSSL_RAW_DATA);
- $v = json_decode($result, true);
- return $v;
- }
- }
- function merchant_id()
- {
- return request()->header('merchant-id', request()->get('merchant_id', 0));
- }
- function source_type()
- {
- return request()->header('source-type', request()->get('source_type', 'wechat'));
- }
- function return_json($msg, $code = 500)
- {
- header('content-type:application/json;charset=utf-8');
- $msg = ['message' => $msg, 'status_code' => $code];
- echo json_encode($msg, true);
- die();
- }
- function path_to_url($path, $disk = 'public')
- {
-
- if (\Illuminate\Support\Str::startsWith($path, ['http://', 'https://'])) {
- return $path;
- }
- return \Illuminate\Support\Facades\Storage::disk($disk)->url($path);
- }
- function api_route($name, $v = 'v1')
- {
- return app('Dingo\Api\Routing\UrlGenerator')->version($v)->route($name);
- }
- function f_money($money, $sed = ',')
- {
- return number_format($money, 2, '.', $sed);
- }
- function php2js($arr)
- {
- return json_encode($arr, true);
- }
- function js2php($json)
- {
- return json_decode($json, true);
- }
- function arr2option($arr)
- {
- return collect($arr)->map(function ($key, $val) {
- return [
- 'label' => $key,
- 'value' => $val,
- 's_value' => (string)$val
- ];
- })->values();
- }
- function str2arr($str, $glue = ',')
- {
- return explode($glue, $str);
- }
- function arr2str($arr, $glue = ',')
- {
- return implode($glue, array_wrap($arr));
- }
- function wechat_fee($money)
- {
- return ($money * 100);
- }
- function idCard2age($id_card)
- {
- $year = substr($id_card, 6, 4);
- $monthDay = substr($id_card, 10, 4);
- $age = date('Y') - $year;
- if ($monthDay > date('md')) {
- $age--;
- }
- return $age;
- }
- function now()
- {
- return date('Y-m-d H:i:s');
- }
- function getDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit = 2, $decimal = 2)
- {
- $EARTH_RADIUS = 6370.996;
- $PI = 3.1415926;
- $radLat1 = $latitude1 * $PI / 180.0;
- $radLat2 = $latitude2 * $PI / 180.0;
- $radLng1 = $longitude1 * $PI / 180.0;
- $radLng2 = $longitude2 * $PI / 180.0;
- $a = $radLat1 - $radLat2;
- $b = $radLng1 - $radLng2;
- $distance = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
- $distance = $distance * $EARTH_RADIUS * 1000;
- if ($unit == 2) {
- $distance = $distance / 1000;
- }
- $distance = round($distance, $decimal);
- return $distance;
- }
- function mobile_hidden($mobile)
- {
- return substr_replace($mobile, '****', 3, 4);
- }
- function format_mileage($km)
- {
- if ($km >= 1) {
- return "{$km}km";
- } else {
- $m = $km * 1000;
- return "{$m}m";
- }
- }
- function format_minutes($min)
- {
- $hours = 0;
- if ($min >= 60) {
- $hours = floor($min / 60);
- }
- $minute = $min % 60;
- $str = '';
- if ($hours) {
- $str .= "{$hours}小时";
- }
- if ($minute) {
- $str .= "{$minute}分";
- }
- return $str;
- }
- function order_repeat($no)
- {
- $order = str2arr($no, '-')[0];
- return $order . '-' . rand(1, 9);
- }
- function curl_get($url)
- {
- $curl = curl_init();
-
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $data = curl_exec($curl);
- curl_close($curl);
- return js2php($data);
- }
- function makeNoTag($tag)
- {
- return config('bike.no_tag') . $tag;
- }
|