1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045 |
- <?php
- /**
- * 获取当前域名
- */
- function _domain()
- {
- return str_replace('https://', '', str_replace('http://', '', url('/')));
- }
- /**
- * 数组转xml
- */
- function arrayToXml($array)
- {
- $xml = '<xml>';
- foreach ($array as $k => $v) {
- $xml .= '<' . $k . '><![CDATA[' . $v . ']]></' . $k . '>';
- }
- $xml .= '</xml>';
- return $xml;
- }
- /**
- * 签名生成
- */
- function _sign($params, $key)
- {
- $signPars = "";
- ksort($params);
- foreach ($params as $k => $v) {
- if ("" != $v && "sign" != $k) {
- $signPars .= $k . "=" . $v . "&";
- }
- }
- $signPars .= "key=" . $key;
- return md5($signPars);
- }
- /**
- * 普通对称校验签名
- */
- function get_sign($params)
- {
- $url = arr_to_url($params, false);
- $url = $url . '&key=' . env('SECRET_KEY');
- // v('get_zw_notify_sign_url:'.$url);
- $sign = md5($url);
- return $sign;
- }
- function arr_to_url($array, $has_sign = false)
- {
- ksort($array);
- reset($array);
- $arg = "";
- while (list($name, $val) = each($array)) {
- if ($name == 'sign' && !$has_sign) continue;
- if (strpos($name, "_") === 0)
- continue;
- if (is_array($val))
- $val = join(',', $val);
- if ($val === "")
- continue;
- $arg .= $name . "=" . $val . "&";
- }
- $arg = substr($arg, 0, count($arg) - 2);
- return $arg;
- }
- /**
- * 获取真实IP
- */
- function _getIp()
- {
- if (getenv('HTTP_X_FORWARDED_FOR')) {
- $ip = getenv('HTTP_X_FORWARDED_FOR');
- } else if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
- $ip = getenv("HTTP_CLIENT_IP");
- else if (getenv("HTTP_X_FORWARD_FOR") && strcasecmp(getenv("HTTP_X_FORWARD_FOR"), "unknown"))
- $ip = getenv("HTTP_X_FORWARD_FOR");
- else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
- $ip = getenv("REMOTE_ADDR");
- else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
- $ip = $_SERVER['REMOTE_ADDR'];
- else
- $ip = "unknown";
- return ($ip);
- }
- /**
- * 数组 转 对象
- * @param array $arr 数组
- * @return object
- */
- function array_to_object($arr)
- {
- if (gettype($arr) != 'array') {
- return;
- }
- foreach ($arr as $k => $v) {
- if (gettype($v) == 'array' || getType($v) == 'object') {
- $arr[$k] = (object) array_to_object($v);
- }
- }
- return (object) $arr;
- }
- /**
- * 对象 转 数组
- * @param object $obj 对象
- * @return array
- */
- function object_to_array($obj)
- {
- $obj = (array) $obj;
- foreach ($obj as $k => $v) {
- if (gettype($v) == 'resource') {
- return;
- }
- if (gettype($v) == 'object' || gettype($v) == 'array') {
- $obj[$k] = (array) object_to_array($v);
- }
- }
- return $obj;
- }
- /**
- * 检查是否为手机号码
- */
- function _isPhone($number)
- {
- return preg_match("/^1[34578][0-9]{9}$/", $number);
- }
- /**
- * 获取渠道域名
- */
- function get_channel_domain($distribution_channel_id)
- {
- return env('PROTOCOL') . '://' . env('CHANNEL_SITE_PREFIX') . "{$distribution_channel_id}." . env('CHANNEL_MAIN_DOMAIN');
- }
- /**
- * 判断所传的参数是否缺少,如果缺少返回渠道的字段,正确返回0
- * @param array $param
- * @param array $must
- * @return int|mixed
- */
- function checkParam(array $param, array $must)
- {
- foreach ($must as $item) {
- if (array_key_exists($item, $param) && $param[$item] != '') {
- } else {
- return $item;
- }
- }
- return 0;
- }
- /**
- * 获取省份城市列表
- */
- function _cities()
- {
- $cities_json = '{"北京市":["北京市"],"天津市":["天津市"],"河北省":["石家庄市","唐山市","秦皇岛市","邯郸市","邢台市","保定市","张家口市","承德市","沧州市","廊坊市","衡水市"],"山西省":["太原市","大同市","阳泉市","长治市","晋城市","朔州市","晋中市","运城市","忻州市","临汾市","吕梁市"],"内蒙古自治区":["呼和浩特市","包头市","乌海市","赤峰市","通辽市","鄂尔多斯市","呼伦贝尔市","巴彦淖尔市","乌兰察布市","兴安盟","锡林郭勒盟","阿拉善盟"],"辽宁省":["沈阳市","大连市","鞍山市","抚顺市","本溪市","丹东市","锦州市","营口市","阜新市","辽阳市","盘锦市","铁岭市","朝阳市","葫芦岛市"],"吉林省":["长春市","吉林市","四平市","辽源市","通化市","白山市","松原市","白城市","延边朝鲜族自治州"],"黑龙江省":["哈尔滨市","齐齐哈尔市","鸡西市","鹤岗市","双鸭山市","大庆市","伊春市","佳木斯市","七台河市","牡丹江市","黑河市","绥化市","大兴安岭地区"],"上海市":["上海市"],"江苏省":["南京市","无锡市","徐州市","常州市","苏州市","南通市","连云港市","淮安市","盐城市","扬州市","镇江市","泰州市","宿迁市"],"浙江省":["杭州市","宁波市","温州市","嘉兴市","湖州市","绍兴市","金华市","衢州市","舟山市","台州市","丽水市"],"安徽省":["合肥市","芜湖市","蚌埠市","淮南市","马鞍山市","淮北市","铜陵市","安庆市","黄山市","滁州市","阜阳市","宿州市","六安市","亳州市","池州市","宣城市"],"福建省":["福州市","厦门市","莆田市","三明市","泉州市","漳州市","南平市","龙岩市","宁德市"],"江西省":["南昌市","景德镇市","萍乡市","九江市","新余市","鹰潭市","赣州市","吉安市","宜春市","抚州市","上饶市"],"山东省":["济南市","青岛市","淄博市","枣庄市","东营市","烟台市","潍坊市","济宁市","泰安市","威海市","日照市","莱芜市","临沂市","德州市","聊城市","滨州市","菏泽市"],"河南省":["郑州市","开封市","洛阳市","平顶山市","安阳市","鹤壁市","新乡市","焦作市","濮阳市","许昌市","漯河市","三门峡市","南阳市","商丘市","信阳市","周口市","驻马店市"],"湖北省":["武汉市","黄石市","十堰市","宜昌市","襄阳市","鄂州市","荆门市","孝感市","荆州市","黄冈市","咸宁市","随州市","恩施土家族苗族自治州"],"湖南省":["长沙市","株洲市","湘潭市","衡阳市","邵阳市","岳阳市","常德市","张家界市","益阳市","郴州市","永州市","怀化市","娄底市","湘西土家族苗族自治州"],"广东省":["广州市","韶关市","深圳市","珠海市","汕头市","佛山市","江门市","湛江市","茂名市","肇庆市","惠州市","梅州市","汕尾市","河源市","阳江市","清远市","东莞市","中山市","潮州市","揭阳市","云浮市"],"广西壮族自治区":["南宁市","柳州市","桂林市","梧州市","北海市","防城港市","钦州市","贵港市","玉林市","百色市","贺州市","河池市","来宾市","崇左市"],"海南省":["海口市","三亚市","三沙市","儋州市"],"重庆市":["重庆市"],"四川省":["成都市","自贡市","攀枝花市","泸州市","德阳市","绵阳市","广元市","遂宁市","内江市","乐山市","南充市","眉山市","宜宾市","广安市","达州市","雅安市","巴中市","资阳市","阿坝藏族羌族自治州","甘孜藏族自治州","凉山彝族自治州"],"贵州省":["贵阳市","六盘水市","遵义市","安顺市","毕节市","铜仁市","黔西南布依族苗族自治州","黔东南苗族侗族自治州","黔南布依族苗族自治州"],"云南省":["昆明市","曲靖市","玉溪市","保山市","昭通市","丽江市","普洱市","临沧市","楚雄彝族自治州","红河哈尼族彝族自治州","文山壮族苗族自治州","西双版纳傣族自治州","大理白族自治州","德宏傣族景颇族自治州","怒江傈僳族自治州","迪庆藏族自治州"],"西藏自治区":["拉萨市","日喀则市","昌都市","林芝市","山南市","那曲地区","阿里地区"],"陕西省":["西安市","铜川市","宝鸡市","咸阳市","渭南市","延安市","汉中市","榆林市","安康市","商洛市"],"甘肃省":["兰州市","嘉峪关市","金昌市","白银市","天水市","武威市","张掖市","平凉市","酒泉市","庆阳市","定西市","陇南市","临夏回族自治州","甘南藏族自治州"],"青海省":["西宁市","海东市","海北藏族自治州","黄南藏族自治州","海南藏族自治州","果洛藏族自治州","玉树藏族自治州","海西蒙古族藏族自治州"],"宁夏回族自治区":["银川市","石嘴山市","吴忠市","固原市","中卫市"],"新疆维吾尔自治区":["乌鲁木齐市","克拉玛依市","吐鲁番市","哈密市","昌吉回族自治州","博尔塔拉蒙古自治州","巴音郭楞蒙古自治州","阿克苏地区","克孜勒苏柯尔克孜自治州","喀什地区","和田地区","伊犁哈萨克自治州","塔城地区","阿勒泰地区"],"台湾省":[],"香港特别行政区":[],"澳门特别行政区":[]}';
- return json_decode($cities_json, 1);
- }
- /**
- * 对象 转 数组
- * @param object $obj 对象
- * @return array
- */
- function ignoreKeyInArray($targetArray, $delete_keys = [], $changes = [])
- {
- $change_keys = array_keys($changes);
- foreach ($targetArray as $key => $value) {
- if (in_array($key, $delete_keys) && isset($targetArray[$key])) unset($targetArray[$key]);
- if (in_array($key, $change_keys) && isset($targetArray[$key])) $targetArray[$key] = $changes[$key];
- if (is_array($value)) ignoreKeyInArray($value, $delete_keys, $change_keys);
- }
- return $targetArray;
- }
- function itemTransform($trans, $data)
- {
- if ($data) {
- return $trans->transform($data);
- } else {
- return [];
- }
- }
- function collectionTransform($trans, $data)
- {
- $ret_data = [];
- if ($data) {
- foreach ($data as $item) {
- $ret_data[] = $trans->transform($item);
- }
- }
- return $ret_data;
- }
- function paginationTransform($trans, $paginator)
- {
- $ret = [];
- $ret['list'] = [];
- if ($paginator) {
- foreach ($paginator as $item) {
- $ret['list'][] = $trans->transform($item);
- }
- $ret['meta'] = [
- 'total' => (int) $paginator->total(),
- 'per_page' => (int) $paginator->perPage(),
- 'current_page' => (int) $paginator->currentPage(),
- 'last_page' => (int) $paginator->lastPage(),
- 'next_page_url' => (string) $paginator->nextPageUrl(),
- 'prev_page_url' => (string) $paginator->previousPageUrl()
- ];
- }
- return $ret;
- }
- function ImageNewsToArray($datas)
- {
- if (empty($datas)) return null;
- if (!is_array($datas)) {
- $datas = json_decode($datas);
- }
- $send_data = array();
- foreach ($datas as $no => $data) {
- foreach ($data as $_data) {
- foreach ($_data as $key => $one_data) {
- $send_data[$no][$key] = $one_data;
- }
- }
- }
- return $send_data;
- }
- /**
- * 加密site id
- */
- function encodeDistributionChannelId($id)
- {
- $encrypt_pool = ['14' => 'xyvz5mexll52mzn4', '13' => 'laosiji', '4372' => 'qhyeyue', '365' => 'vciam5tg71', '384' => 'sdxisd', '5795' => 'gyp23fzu'];
- if (isset($encrypt_pool[$id])) {
- return $encrypt_pool[$id];
- }
- /*$db_encrypt_info = \DB::table('distribution_channel_id_encrypt')
- ->where('distribution_channel_id',$id)
- ->where('is_enable',1)
- ->select('en_distribution_channel_id')
- ->first();
- if($db_encrypt_info && $db_encrypt_info->en_distribution_channel_id){
- return $db_encrypt_info->en_distribution_channel_id;
- }*/
- $hashids = new \Hashids\Hashids('', 16, 'abcdefghjklmnopqrstuvwxyz1234567890');
- return $hashids->encode($id);
- }
- /**
- * 解密密site id
- */
- function decodeDistributionChannelId($code)
- {
- $encrypt_pool = ['xyvz5mexll52mzn4' => '14', 'laosiji' => '13', 'qhyeyue' => '4372', 'vciam5tg71' => '365', 'sdxisd' => '384', 'gyp23fzu' => '5795'];
- if (isset($encrypt_pool[$code])) {
- return $encrypt_pool[$code];
- }
- /*$db_encrypt_info = \DB::table('distribution_channel_id_encrypt')
- ->where('en_distribution_channel_id',$code)
- ->where('is_enable',1)
- ->select('distribution_channel_id')
- ->first();
- if($db_encrypt_info && $db_encrypt_info->distribution_channel_id){
- return $db_encrypt_info->distribution_channel_id;
- }*/
- $hashids = new \Hashids\Hashids('', 16, 'abcdefghjklmnopqrstuvwxyz1234567890');
- $res = $hashids->decode($code);
- if ($res && isset($res[0])) {
- return $res[0];
- }
- return null;
- }
- //bid加密
- function book_hash_encode($bid)
- {
- return Vinkla\Hashids\Facades\Hashids::encode($bid);
- }
- //bid解密
- function book_hash_decode($encrypt_bid)
- {
- return Vinkla\Hashids\Facades\Hashids::decode($encrypt_bid);
- }
- /**
- * 保存Excel格式数据表 需要composer require phpoffice/phpspreadsheet
- * @param $header
- * @param $data
- * @param $path eg. storage_path('app/excel.xlsx')
- * @param $remark array $remark['cell']备注单元格 ¥remark['contents']备注内容
- */
- function saveExcelData($header, $data, $path, $remark = '')
- {
- $objPHPExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
- // Set document properties
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle('Phpmarker-' . date('Y-m-d'));
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $objPHPExcel->setActiveSheetIndex(0);
- //设置header
- if (!is_array($header)) {
- return false;
- }
- $ini = 65; //A的acsii码
- foreach ($header as $value) {
- $objPHPExcel->getActiveSheet()->getColumnDimension(chr($ini))->setAutoSize(true);
- $objPHPExcel->getActiveSheet()->setCellValue(chr($ini++) . '1', $value);
- }
- if (!is_array($data)) {
- return false;
- }
- $i = 2;
- foreach ($data as $val) {
- $ini = 65;
- foreach ($val as $item) {
- $objPHPExcel->getActiveSheet()->setCellValue(chr($ini++) . $i, $item);
- }
- ++$i;
- }
- if ($remark) {
- $conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
- $conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
- ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN)
- ->addCondition('200')
- ->addCondition('400');
- $conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_YELLOW);
- foreach ($remark as $key => $value) {
- $conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle($value['cell'])->getConditionalStyles();
- $conditionalStyles[] = $conditional1;
- $objPHPExcel->getActiveSheet()->getStyle($value['cell'])->setConditionalStyles($conditionalStyles);
- $objPHPExcel->getActiveSheet()->setCellValue($value['cell'], $value['contents']);
- }
- }
- if (!$path) {
- // Redirect output to a client’s web browser (Xlsx)
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="01simple.xlsx"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
- header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header('Pragma: public'); // HTTP/1.0
- $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
- $writer->save('php://output');
- //return true;
- } else {
- $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
- $writer->save($path);
- }
- }
- function saveExcelDataToMultiSheet(array $param, $path)
- {
- $sheet_num = count($param);
- //\Log::info($sheet_num);
- //\Log::info($param);
- $objPHPExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
- $new_sheet = null;
- for ($j = 0; $j < $sheet_num; $j++) {
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- if ($j > 0) {
- \Log::info('created_sheet');
- $objPHPExcel->createSheet($j);
- //\Log::info($new_sheet);
- }
- $objPHPExcel->setActiveSheetIndex($j);
- // Rename worksheet
- $objPHPExcel->getActiveSheet()->setTitle($param[$j]['title']);
- //设置header
- if (!is_array($param[$j]['header'])) {
- return false;
- }
- $header = $param[$j]['header'];
- $ini = 65; //A的acsii码
- foreach ($header as $value) {
- $objPHPExcel->getActiveSheet()->getColumnDimension(chr($ini))->setAutoSize(true);
- $objPHPExcel->getActiveSheet()->setCellValue(chr($ini++) . '1', $value);
- }
- if (!is_array($param[$j]['data'])) {
- return false;
- }
- $data = $param[$j]['data'];
- $i = 2;
- foreach ($data as $val) {
- $ini = 65;
- foreach ($val as $item) {
- $objPHPExcel->getActiveSheet()->setCellValue(chr($ini++) . $i, $item);
- }
- ++$i;
- }
- }
- $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
- $writer->save($path);
- }
- function myLog($name, $filename = '')
- {
- if (!$filename) {
- $filename = $name;
- }
- $filename = $filename . '.log';
- $logger = new \Monolog\Logger($name);
- $writer = new \Illuminate\Log\Writer($logger);
- $writer->useDailyFiles(storage_path('logs/' . $filename),3);
- return $writer;
- }
- function redisEnv($key, $default = '')
- {
- static $result = [];
- if (isset($result[$key])) return $result[$key];
- $value = \Redis::hget('env', $key);
- if ($value) {
- $result[$key] = $value;
- return $value;
- }
- return $default;
- }
- function redisEnvMulti(...$key)
- {
- $value = \Redis::hmget('env', $key);
- return $value;
- }
- function get_client_ip($type = 0, $adv = false)
- {
- $type = $type ? 1 : 0;
- static $ip = null;
- if (null !== $ip) {
- return $ip[$type];
- }
- if ($adv) {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos) {
- unset($arr[$pos]);
- }
- $ip = trim($arr[0]);
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // IP地址合法验证
- $long = sprintf("%u", ip2long($ip));
- $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
- return $ip[$type];
- }
- //授权两次
- function specialChannelAuthInfo()
- {
- return [
- '4404' => 'wx1d618e3cf988e2e6',
- '4395' => 'wx5135dcdbb6043872',
- '4396' => 'wx8f365ca550b8bf3c',
- '4397' => 'wx83b5939831c13515',
- '4398' => 'wx50dd61b654bbbb9e',
- '4399' => 'wxe01b0f5e3a456d94',
- '4400' => 'wxb98203d36e526fcb',
- '4401' => 'wx4badede056f2e776',
- '4402' => 'wx9a941e981acdeb74',
- '4403' => 'wxef3feefc54f1c6a1',
- '4405' => 'wx2f2c0b2faa0978c9',
- '4406' => 'wx9e911047fc2554d0',
- '4413' => 'wx6e662e3154cc49bd',
- '4414' => 'wx2983fdb0e80431ba',
- '4415' => 'wx4876d3c9ccd07ad6',
- '4416' => 'wx7e51e2825f5aad16',
- //'4433'=>'wx274eb60e7a1fc953',
- //'4434'=>'wx7e06ff61885e50bb',
- '4435' => 'wxe3035fd2e77b7cc8',
- '4436' => 'wx79dbfc1ed7397c28',
- //'4438'=>'wx7af4f5ee84c8b097',
- '4439' => 'wx0789cce3a1699ce8',
- //'4440'=>'wx7f8907c009d3908d',
- '4441' => 'wx01f9731df15a7888',
- '4442' => 'wxb7192d7171ffa3c4',
- '4443' => 'wx3355f5be92b92350',
- '4444' => 'wx431a3a692700b63a',
- '4445' => 'wx3c53a641ee53b984',
- '4456' => 'wxc8c1cfb70e568f0c',
- '976' => 'wx21506dfd22a0dc9c',
- '928' => 'wx76da3531773c1f39',
- '157' => 'wx5ebe6187c0fb0bd5',
- '4175' => 'wx64cf3051ceb145ae',
- '4604' => 'wxc177995c55b5e75e'
- ];
- }
- //授权一次
- function specialChannelAuthInfoV2($distribution_channel_id)
- {
- $info = \Redis::hget('specialChannelAuthInfoV2', $distribution_channel_id);
- $data = [];
- if ($info) {
- $data[$distribution_channel_id] = $info;
- }
- return $data;
- //$info = \Redis::hgetall('specialChannelAuthInfoV2');
- //return $info;
- /*return [
- '4483'=>'wx4651668ca7f6be51',
- '4567'=>'wx2285b54ee5e6e752',
- '4568'=>'wx4cfa12302780e654',
- '4569'=>'wxa25b19c509ba7db5',
- '4578'=>'wx3beda81dba0b450b',
- '4580'=>'wxb4bb620409a96ed7',
- '4603'=>'wxf9df2ce5ea94fa4e',
- //'4604'=>'wxb479d38891b14286',
- '4605'=>'wx72569a8f18599cdb',
- '4606'=>'wxb17c22779a821271',
- '4607'=>'wx2bc3eaf8840f81a8',
- '4608'=>'wx3723054b39225b9d',
- '4609'=>'wx504c20ebf5cfcd60',
- '4617'=>'wxf45639677a2bb97c',
- '4624'=>'wx552c4500db26c627',
- '4658'=>'wx680b1e557a2e811d',
- '4666'=>'wx8136bdaa80a6dda0',
- '4667'=>'wx26608e6bb0705656',
- '4763'=>'wxdd100beddec262c9',
- '4779'=>'wx6f9cd0fcb96d9d9d',
- '4778'=>'wx4e1d53afd5e73b33',
- '4433'=>'wx449a65a9bbc7d50a',
- '4434'=>'wx7ea67b55ac102fd3',
- '4440'=>'wxddd622a5c195a3a9',
- '4438'=>'wx007ef65244b47f7c',
- '4815'=>'wx33f6cc190b194b3e',
- '4839'=>'wx27b946dad6c3aa91',
- '4905'=>'wxe1a06f73c723c2a6',
- '4906'=>'wxf03275b6863c2806',
- '4907'=>'wxadc68453a4500191',
- '4908'=>'wx8d46d69ab9d76c55',
- '4909'=>'wx2c62f7f4a02176d7',
- '4910'=>'wx7ee2ad6685e3d5b3',
- '4820'=>'wx30ecb35d13959f8d',
- '4980'=>'wx002be80fb65d808e',
- '5148'=>'wx8e9ff7a97fa67675',
- '5189'=>'wx475125bc6dd942f9',
- '4941'=>'wxe7f83fba4596cb03',
- '5319'=>'wxa697fd62760dfc53',
- '5365'=>'wx40c098d5ef384b2d',
- '5366'=>'wx1fd33388075778fe',
- '5427'=>'wxb54db864aae35e43',
- '5428'=>'wx46d1c3dc66bb08c6',
- '5429'=>'wx953c1a61bd82a358',
- '5430'=>'wx956fd17a5d81c122',
- '5444'=>'wx3f11071d2c51fe3c',
- '5464'=>'wxe06f1e737730cda8',
- '5225'=>'wx25d970a3f95ebebe',
- '4217'=>'wxdb15f8db194bf6f4',
- '5617'=>'wx94e7c0d2e805ba5e',
- '527'=>'wxbfa2ba3dccf76921',
- '5623'=>'wxe6fa23bd8c26e4a1',
- '5644'=>'wx379246ab67f5ba9b',
- '5645'=>'wx6723f21df29e0eb1',
- '5646'=>'wx28ab08db5717a16d',
- '5647'=>'wx14acfd6563f46ca9',
- '5648'=>'wx3d9d9118751b6caf',
- '5649'=>'wx8b1f11fcc7ba18da',
- '5650'=>'wx5fa6c4a6aa4bdf2a',
- '5651'=>'wxe5ab0cc5f3765329',
- '5652'=>'wx4990a38d72a02577',
- '5653'=>'wxdc09e7629d529a69',
- '5654'=>'wx03f0aa164ea3b4d9',
- '5655'=>'wxd9e763876c55864a',
- '5656'=>'wxd9816239598d8fdb',
- '5657'=>'wxb280a352c0a0ed65',
- '5658'=>'wxd9a6a8b2749717c3',
- '5660'=>'wx2c252d71dce324cb',
- '5661'=>'wxcc024129cf943eda',
- '5631'=>'wxc2282173679eca9f',
- '5632'=>'wxb6cfac3a8618d758',
- '5633'=>'wx7e4038e693ff47b8',
- '5634'=>'wx0521f0de4dfea155',
- '5635'=>'wx32ab656b849bd3b0',
- '5636'=>'wx524790df543980f3',
- '5637'=>'wx52ad84ebd80039fb',
- '5643'=>'wx72037519796b1531',
- '5664'=>'wx9265b52a75ebb042',
- '5638'=>'wx8384f5fb7ab1b19c',
- '5639'=>'wx7f470f3758928718',
- '5640'=>'wxc565bc7bc4a42074',
- '5641'=>'wx7e9d88af5216eedd',
- '5642'=>'wx4618cda729138d15',
- '5662'=>'wx44b8626c8ad9247e',
- '5663'=>'wx8653757301ed2591',
- '5690'=>'wxbdbb2b13eea80db9',
- '5691'=>'wx8b2e50da113c673c',
- '5692'=>'wxb51a74837aa2f1c4',
- '5764'=>'wxdb47c48bbfa19cb7',
- '5808'=>'wx99b70748c46d0533'
- ];*/
- }
- function generateMonthOrderUrl($user_id)
- {
- $app_id = env('MONTH_ORDER_APPID');
- $app_secret = env('MONTH_ORDER_APP_SECRET');
- $key = env('MONTH_ORDER_KEY');
- $plan_id = env('MONTH_ORDER_PLAN_ID');
- $ip = _getIp();
- $sign = _sign(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip'), $key . $key);
- $sign = strtoupper($sign);
- $return_web = 1;
- $url = 'http://pap.manyuedu.org/?' . http_build_query(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip', 'sign', 'return_web'));
- return $url;
- }
- function generateMonthOrderUrlV2($user_id, $plan_id, $ip)
- {
- $app_id = env('MONTH_ORDER_APPID');
- $app_secret = env('MONTH_ORDER_APP_SECRET');
- $key = env('MONTH_ORDER_KEY');
- $sign = _sign(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip'), $key . $key);
- $sign = strtoupper($sign);
- $return_web = 1;
- $url = 'http://pap.manyuedu.org/?' . http_build_query(compact('app_id', 'app_secret', 'plan_id', 'user_id', 'ip', 'sign', 'return_web'));
- return $url;
- }
- function getMillisecond()
- {
- list($microsecond, $time) = explode(' ', microtime());
- return (float) sprintf('%.0f', (floatval($microsecond) + floatval($time)) * 1000);
- }
- /**
- * CURL发送post请求
- * @param $url
- * @param null $data
- * @param bool $json
- * @return bool|string
- */
- function httpPostRequest($url, $data = null, $json = FALSE)
- {
- //创建了一个curl会话资源,成功返回一个句柄;
- $curl = curl_init();
- //设置url
- curl_setopt($curl, CURLOPT_URL, $url);
- //设置为FALSE 禁止 cURL 验证对等证书(peer’s certificate)
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- //设置为 1 是检查服务器SSL证书中是否存在一个公用名(common name)
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
- if (!empty($data)) {
- //设置请求为POST
- curl_setopt($curl, CURLOPT_POST, 1);
- //curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); //最长的可忍受的连接时间
- //设置POST的数据域
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- if ($json) {
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt(
- $curl,
- CURLOPT_HTTPHEADER,
- array(
- 'Content-Type: application/json; charset=utf-8',
- 'Content-Length: ' . strlen($data)
- )
- );
- }
- }
- //设置是否将响应结果存入变量,1是存入,0是直接输出
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- //然后将响应结果存入变量
- $output = curl_exec($curl);
- //关闭这个curl会话资源
- curl_close($curl);
- return $output;
- }
- /**
- * 获取对象或数组的属性值
- * @param $param
- * @param $key
- * @param string $default
- * @return mixed|string
- */
- function getProp($param, $key, $default = '')
- {
- $result = $default;
- if (is_object($param) && isset($param->$key)) {
- $result = $param->$key;
- }
- if (is_array($param) && isset($param[$key])) {
- $result = $param[$key];
- }
- return $result;
- }
- /**
- * 求最大公约数 Greatest Common Divisor(GCD)
- * @param $a
- * @param $b
- * @return int
- */
- function gcd($a, $b)
- {
- // 防止因除数为0而崩溃
- if ($a === 0 || $b === 0) {
- return 1;
- }
- if ($a % $b === 0) {
- return $b;
- }
- return gcd($b, $a % $b);
- }
- /**
- * 格式化比例值
- * @param $value1
- * @param $value2
- * @param $gcd
- * @return array|float[]|int[]
- */
- function proportion($value1, $value2, $gcd)
- {
- if ($gcd === 0) {
- return [$value1, $value2];
- }
- return [$value1 / $gcd, $value2 / $gcd];
- }
- /**
- * 钉钉通知异常
- * @param $message
- */
- function sendNotice($message)
- {
- $webHook = config('common.dingTalk');
- $data = [
- 'msgtype' => 'text',
- 'text' => [
- 'content' => $message
- ],
- 'at' => [
- // 'atMobiles' => [
- // '13127819373'
- // ],
- 'isAll' => true
- ]
- ];
- httpPostRequest($webHook, json_encode($data), true);
- }
- /**
- * 获取隐藏cp
- * @param string $package 包名/包id/站点id
- * @param $type 0 是包名 ;1 是包id;2是站点id
- * @return false|string[]
- */
- function getHiddenCp($package = "",$type = 0)
- {
- if (empty($package)){
- return array_filter(explode(',',env('HIDDEN_CP_SOURCE')));
- }
- if ($type == 0){
- $data = \DB::table('qapp_package_info')->where('package','=',$package)->value('reject_cp');
- }else if($type == 1){
- $data = \DB::table('qapp_package_info')->where('id','=',$package)->value('reject_cp');
- }else if($type == 2) {
- $data = \DB::table('qapp_package_info')->where('channel_id','=',$package)->value('reject_cp');
- }else{
- $data = null;
- }
- if (empty($data)){
- return array_filter(explode(',',env('HIDDEN_CP_SOURCE')));
- }
- return explode(',',$data);
- }
- /**
- * 包名替换
- * @param $name
- * @return string
- */
- function get_real_package($name)
- {
- switch($name)
- {
- case 'com.beidao.kuaiying.haohan':
- $package = 'com.beidao.kuaiying.haitian';
- break;
- case 'com.beidao.kuaiying.haohannew':
- $package = 'com.beidao.kuaiying.haohan';
- break;
- default:
- $package = $name;
- break;
- }
- return $package;
- }
- if (!function_exists("check_qapp_auth")){
- function check_qapp_auth($package = "",$isPackageId = 0)
- {
- if (empty($package)){
- return false;
- }
- if ($isPackageId == 0){
- $data = \DB::table('qapp_package_info')->where('package','=',$package)->value('cp_author_status');
- }else{
- $data = \DB::table('qapp_package_info')->where('id','=',$package)->value('cp_author_status');
- }
- if ($data == 1){
- return true;
- }
- return false;
- }
- }
- /**
- *
- * name: check_qapp_send_order_id
- * 判断派单id是否属于所访问的站点
- * @param mixed $channelId 站点id
- * @param mixed $sendOrderId 派单id
- * @return bool
- * date 2022/09/09 10:50
- */
- if (!function_exists("check_qapp_send_order_id)")){
- function check_qapp_send_order_id($channelId = 0 ,$sendOrderId = 0){
- if ($sendOrderId < 1 || $channelId < 1){
- return false;
- }
- $sendOrderChannelId = Redis::hGet("qapp:send_order:distribution_channel",$sendOrderId);
- if ($sendOrderChannelId < 1 ){
- $sendOrderChannelId = \DB::table('qapp_send_orders')->where('send_order_id','=',$sendOrderId)->value('distribution_channel_id');
- if ($sendOrderChannelId > 0 ){
- Redis::hSet("qapp:send_order:distribution_channel",$sendOrderId,$sendOrderChannelId);
- }
- }
- if (trim($channelId) !== trim($sendOrderChannelId)){
- myLog("QuickAppSendOrderError")->info("派单渠道和包名不匹配: send_order_id = {$sendOrderId};sned_order_id_channel_id= {$sendOrderChannelId};channel_id= {$channelId} ");
- return false;
- }
- return true;
- }
- }
- if(!function_exists("str_decode")){
- /**
- * 字符解密
- * name: str_decode
- * @param $str
- * @return int
- * date 2022/09/27 11:38
- */
- function str_decode($str){
- $decode = Hashids::decode($str);
- $decode = is_array($decode) ? array_shift($decode) : $decode;
- if(empty($decodeBid)){
- myLog("StrDecodeError")->info("str : {$str}, decode : ".var_export($decode,true));
- }
- return intval($decode);
- }
- }
- if (!function_exists('str_encode')){
- /***
- * 字符加密
- * name: str_decode
- * @param mixed $str
- * @return mixed
- * date 2022/09/27 11:38
- */
- function str_encode($str)
- {
- return Hashids::encode($str);
- }
- }
- if(!function_exists('get_special_bid')){
- function get_special_bid()
- {
- return [];
- // return [7742,7743,7748,8721,8749,64870,64871,64872,64873,64874,64875,64876,64877,64878,64879,64880,64881,64882,64883,64884,64885,64886,64887,64888,64889,64890,64891,64892,64893,64894,64895,64896,64897,64900,64899,64898];
- }
- }
- /**
- * 判断包是否是公共包
- * name: is_public_package
- * @param string $packageName
- * @return bool
- * date 2022/09/22 16:53
- */
- if(!function_exists("is_public_package")){
- function is_public_package($packageName = "")
- {
- if (empty($packageName)){
- return false;
- }
- $publicPackageName = get_public_packages();
- if (in_array($packageName,$publicPackageName)){
- return true;
- }
- return false;
- }
- }
- /**
- * 判断包是否是公共包站点id
- * name: is_public_package
- * @param string $packageName
- * @return bool
- * date 2022/09/22 16:53
- */
- if(!function_exists("is_public_package_channel_id")){
- function is_public_package_channel_id($channelId = 0)
- {
- if (empty($$channelId)){
- return false;
- }
- $publicPackageName = get_public_package_channel_ids();
- if (in_array($channelId,$publicPackageName)){
- return true;
- }
- return false;
- }
- }
- /**
- * 所有获取公共包
- * name: get_public_packages
- * @return \Illuminate\Config\Repository|\Illuminate\Foundation\Application|mixed
- * date 2022/09/22 17:24
- */
- if(!function_exists('get_public_packages')){
- function get_public_packages(){
- return config("package.package_name");
- }
- }
- /**
- * 所有获取公共包站点id
- * name: get_public_packages
- * @return \Illuminate\Config\Repository|\Illuminate\Foundation\Application|mixed
- * date 2022/09/22 17:24
- */
- if(!function_exists('get_public_package_channel_ids')){
- function get_public_package_channel_ids(){
- return config("package.channel_id");
- }
- }
- /***
- * 获取默认公共包站点id
- * name: get_default_public_channel_id
- * @return int|mixed
- * date 2022/09/23 14:51
- */
- if (!function_exists("get_default_public_channel_id")){
- function get_default_public_channel_id()
- {
- $package = get_default_public_package_info();
- return $package['channel_id'] ?? 0;
- }
- }
- /***
- * 获取默认公共包站点id和包名
- * name: get_default_public_package_info
- * @return \Illuminate\Config\Repository|\Illuminate\Foundation\Application|mixed
- * date 2022/09/23 14:51
- */
- if (!function_exists("get_default_public_channel_id")){
- function get_default_public_package_info()
- {
- return config("package.default");
- }
- }
- if(function_exists('get_rejcet_cp_by_package_name')){
- function get_rejcet_cp($package = "",$isPackageId = 0){
- if (empty($package)){
- return false;
- }
- if ($isPackageId == 0){
- $data = \DB::table('qapp_package_info')->where('package','=',$package)->value('cp_author_status');
- }else{
- $data = \DB::table('qapp_package_info')->where('id','=',$package)->value('cp_author_status');
- }
- }
- }
|