2 && $agoDay < 16) { $result = $agoDay . '天前 ' . date('H:i', $targetTime); } else { $format = date('Y') != date('Y', $targetTime) ? "Y-m-d H:i" : "m-d H:i"; $result = date($format, $targetTime); } return $result; } /** * 获取年龄 * @param string $birthday 生日 * @return integer 年龄 */ public function getAge($birthday) { if (empty($birthday)) { return 0; } $age = strtotime($birthday); if ($age === false) { return 0; } list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age)); $now = strtotime("now"); list($y2, $m2, $d2) = explode("-", date("Y-m-d", $now)); $age = $y2 - $y1; if ((int) ($m2 . $d2) < (int) ($m1 . $d1)) $age -= 1; return $age; } /** * 年龄转成时间 */ public function agetobirthday($age, $symbol = '-') { $age = $age == 0 ? 25 : $age; $nowyear = date("Y", time()); $year = $nowyear - $age; $monthArr = []; for ($i = 1; $i < 13; $i++) { $monthArr[] = $i < 10 ? '0' . $i : $i; } $dayArr = []; for ($i = 1; $i < 29; $i++) { $dayArr[] = $i < 10 ? '0' . $i : $i; } $month_key = array_rand($monthArr, 1); $month = $monthArr[$month_key]; $date_tmp_stamp = strtotime($year . '-' . $month); $day = ''; if ($month == '02' && date("t", $date_tmp_stamp) == '29') { $dayArr = array_merge($dayArr, ['29']); $day_key = array_rand($dayArr, 1); $day = $dayArr[$day_key]; } else if ($month == '02' && date("t", $date_tmp_stamp) == '28') { $day_key = array_rand($dayArr, 1); $day = $dayArr[$day_key]; } else if (in_array($month, ['01', '03', '05', '07', '08', '10', '12'])) { $dayArr = array_merge($dayArr, ['29', '30', '31']); $day_key = array_rand($dayArr, 1); $day = $dayArr[$day_key]; } else { $dayArr = array_merge($dayArr, ['29', '30']); $day_key = array_rand($dayArr, 1); $day = $dayArr[$day_key]; } return $year . $symbol . $month . $symbol . $day; } public function ageToDate($age) { $month_day = date('m-d'); $year = date('Y') - $age; return $year . '-' . $month_day; } public function searchAge($age) { // $start_time = ''; // $end_time = ''; if ($age == '00后') { $start_time = "2000-01-01"; $end_time = "2010-01-01"; } elseif ($age == '90后') { $start_time = "1990-01-01"; $end_time = "20001-01-01"; } elseif ($age == "80后") { $start_time = "1980-01-01"; $end_time = "1990-01-01"; } elseif ($age == "70后") { $start_time = "1970-01-01"; $end_time = "1980-01-01"; } elseif ($age == "60后") { $start_time = "1960-01-01"; $end_time = "1970-01-01"; } elseif ($age == "50后") { $start_time = "1950-01-01"; $end_time = "1960-01-01"; } elseif ($age == "40后") { $start_time = "1940-01-01"; $end_time = "1950-01-01"; } else { $start_time = "1940-01-01"; $end_time = date('Y-m-d', time()); } $result = [ 'start_time' => $start_time, 'end_time' => $end_time, ]; return $result; } /** * 随机生成16位数,作为本地服务器的支付订单ID * @return type */ public function getTradeNO() { $dateline = time(); $mix_1 = rand(100, 999); $mix_2 = rand(100, 999); return $dateline . $mix_1 . $mix_2; } public function getAliTradeNo() { $dateline = time(); $mix_1 = rand(100, 999); $mix_2 = rand(100, 999); return 'ali' . $dateline . $mix_1 . $mix_2; } /** * 随机生成16位数退款订单号 * @return string 退款订单号 */ public function getRefundTradeNo() { $dateline = time(); $mix_1 = rand(100, 999); $mix_2 = rand(10, 99); return 'r' . $dateline . $mix_1 . $mix_2; } //发送普通消息 function sentMessage($mobile, $message) { Message::create([ 'phone' => $mobile, 'message' => $message, 'confirmed' => 1, 'ip' => request() ? request()->ip() : '127.0.0.1', ]); Messenger::sendSMS($mobile, $message); return true; } /** * 时间段 * @param [type] $start_time [description] * @param [type] $end_time [description] * @return [type] [description] */ public function daliy($start_time, $end_time) { $strtime1 = strtotime($start_time); $strtime2 = strtotime($end_time); $day_arr[] = date('Y-m-d', $strtime1); // 当前月; while (($strtime1 = strtotime('+1 day', $strtime1)) <= $strtime2) { $day_arr[] = date('Y-m-d', $strtime1); // 取得递增月; } return $day_arr; } public function randAmount() { $array = [3, 3, 3, 3, 4, 4, 4, 5, 5, 6]; $key = array_rand($array); $amount = $array[$key] / 10 + mt_rand(0, 9) / 100; $data = ['type' => 'normal', 'num' => 1, 'amount' => $amount]; return $data; } /** * 小程序注册红包 */ public function mpRegisterRedAmount() { $array = [3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8, 9]; $key = array_rand($array); $amount = $array[$key] / 10 + mt_rand(0, 9) / 100; return $amount; } /** * 文本内容检测 阿里云 */ public function textContentCecurity($content_arr) { $tasks = []; foreach ($content_arr as $content) { if (!empty($content)) { $tasks[] = ["content" => $content]; } } $body = json_encode([ "scenes" => ["antispam"], "tasks" => $tasks, ]); $uri = '/green/text/scan'; //获取结果 $result = $this->contentCecurity($uri, $body); //分析结果 $result = $this->getContentCecurityResult($result); //\Log::info($result); return $result; } /** * 图片内容检测 */ public function imageContentCecurity($img_url_arr, $scenes = ["porn", "terrorism", "ad", "live", "qrcode", "logo"]) { $tasks = []; foreach ($img_url_arr as $img_url) { if (!empty($img_url)) { $tasks[] = ["url" => $img_url]; } } $body = json_encode([ "scenes" => $scenes, "tasks" => $tasks, ]); $uri = '/green/image/scan'; //获取结果 $result = $this->contentCecurity($uri, $body); //分析结果 $result = $this->getImageContentCecurityResult($result); return $result; } /** * 内容安全检测 */ public function contentCecurity($uri, $body) { try { //加密后的body $content_md5 = base64_encode(md5($body, true)); //获取签名 $param = $this->makeSignature($content_md5, $uri); //授权认证 $authorization = "acs" . " " . $param['accessKeyId'] . ":" . $param['signature']; //获取公共参数 $common_param = $this->commonParam($content_md5, $param, $authorization); $method = 'POST'; $host = "https://green.cn-shanghai.aliyuncs.com"; $url = $host . $uri; $result = Http::aliyunHttp($url, $body, $method, $common_param); return $result; } catch (Exception $e) { $this->getError($e); \Log::ERROR($e->getErrorMessage()); return false; } } /** * 文内内容结果 */ public function getContentCecurityResult($result) { if (isset($result->code) && $result->code == 200) {//成功 foreach ($result->data as $data) { $results = $data->results; $label = ($results[0])->label; if ($label === 'normal') { continue; } $re = $this->contentResult($label); return ['result' => $re, 'context' => $data->content]; } } else { return ['result' => null]; } } /** * 图片内容分析结果 */ public function getImageContentCecurityResult($result) { if (isset($result->code) && $result->code == 200) {//成功 // $data = ($result->data)[0]; foreach ($result->data as $data) { if ($data->code == 200) { $results = $data->results; foreach ($results as $re) { $suggestion = $re->suggestion; if ($suggestion == 'pass' || $suggestion == "review") continue; // $rate = $re->rate; // if ($rate < 80) continue; $label = $re->label; $scene = $re->scene; $re = $this->getImagecontentResult($label, $scene, $suggestion); return ['result' => $re, 'url' => $data->url]; } } else { return ['result' => null]; } } } else { return ['result' => null]; } } public function getImagecontentResult($label, $scen, $suggestion) { if ($label == 'normal') return null; $str = $suggestion != 'block' ? $str = '疑似' : '涉嫌'; switch ($scen) { case 'porn': if ($label == 'sexy') { $str = $str . '暴露'; } else { $str = $str . '涉黄'; } break; case 'terrorism': $str = $str . '暴恐涉政'; break; case 'ad': $str = $str . '图文违规'; break; case 'qrcode': $str = $str . '图片二维码'; break; case 'live': $str = $str . '不良场景'; break; case 'logo': $str = $str . '商标'; break; default: $str = null; break; } return $str; // $data = [ // "normal"=>null,//正常文本 // "sexy"=>"暴露", // "porn"=>"色情", // "bloody"=>"血腥", // "explosion"=>'爆炸烟光', // "politics"=>"涉政", // "terrorism"=>"暴恐涉政", // "violence"=>"打斗", // 'carcrash'=>'车祸现场', // ]; // if (!isset($data[$label])) { // return null; // } } public function contentResult($label) { $data = [ "normal" => null,//正常文本 "spam" => "含垃圾信息", "ad" => "广告", "politics" => "涉政", "terrorism" => "暴恐", "abuse" => "辱骂", "porn" => "色情", "flood" => "灌水", "contraband" => "违禁", "meaningless" => "无意义", // "customized"=>"自定义(例如命中自定义关键词)", ]; return $data[$label]; } /** * 获取签名 */ public static function makeSignature($content_md5, $uri) { $date = gmdate('l, d F Y H:i:s') . ' GMT'; $accessKeyId = env('ACCESS_KEY_ID'); $secret = env("ACCESS_KEY_SECRET"); $x_acs_version = '2018-05-09'; $x_acs_signature_version = '1.0'; $x_acs_signature_method = 'HMAC-SHA1'; $strs = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"; $x_acs_signature_nonce = substr(str_shuffle($strs), mt_rand(0, strlen($strs) - 11), 10); $http_x_acs_str = "x-acs-signature-method:" . $x_acs_signature_method . "\n" . "x-acs-signature-nonce:" . $x_acs_signature_nonce . "\n" . "x-acs-signature-version:" . $x_acs_signature_version . "\n" . "x-acs-version:" . $x_acs_version; $str = "POST" . "\n" . "application/json" . "\n" . $content_md5 . "\n" . "application/json" . "\n" . $date . "\n" . $http_x_acs_str . "\n" . $uri; $signature = base64_encode(hash_hmac('sha1', $str, $secret, true)); $param = [ 'x_acs_signature_version' => $x_acs_signature_version, 'x_acs_version' => $x_acs_version, 'x_acs_signature_nonce' => $x_acs_signature_nonce, 'x_acs_signature_method' => $x_acs_signature_method, 'signature' => $signature, 'date' => $date, 'accessKeyId' => $accessKeyId, ]; return $param; } /** * 请求头参数 */ public function commonParam($content_md5, $param, $authorization) { $common_param = [ 'Accept: application/json', 'Content-Type: application/json', 'Content-MD5: ' . $content_md5, 'Date: ' . $param['date'], 'x-acs-version: ' . $param['x_acs_version'], 'x-acs-signature-nonce: ' . $param['x_acs_signature_nonce'], 'x-acs-signature-version: ' . $param['x_acs_signature_version'], 'x-acs-signature-method: ' . $param['x_acs_signature_method'], 'Authorization: ' . $authorization ]; return $common_param; } public function checkCardBirhday($IDCard) { $result['error'] = 0;//0:未知错误,1:身份证格式错误,2:无错误 $result['flag'] = '';//0标示成年,1标示未成年 $result['tdate'] = '';//生日,格式如:2012-11-15
  $tdate = ''; if (!preg_match("/^[1-9]([0-9a-zA-Z]{17}|[0-9a-zA-Z]{14})$/i", $IDCard)) { $result['error'] = 1; return $result; } else { if (strlen($IDCard) == 18) { $tyear = intval(substr($IDCard, 6, 4)); $tmonth = substr($IDCard, 10, 2); $tday = substr($IDCard, 12, 2); if ($tyear > date("Y") || $tyear < (date("Y") - 100)) { $flag = 0; } elseif ($tmonth < 0 || $tmonth > 12) { $flag = 0; } elseif ($tday < 0 || $tday > 31) { $flag = 0; } else { $tdate = $tyear . "-" . $tmonth . "-" . $tday; if ((time() - mktime(0, 0, 0, $tmonth, $tday, $tyear)) > 18 * 365 * 24 * 60 * 60) { $flag = 0; } else { $flag = 1; } } } elseif (strlen($IDCard) == 15) { $tyear = intval("19" . substr($IDCard, 6, 2)); $tmonth = intval(substr($IDCard, 8, 2)); $tday = intval(substr($IDCard, 10, 2)); if ($tyear > date("Y") || $tyear < (date("Y") - 100)) { $flag = 0; } elseif ($tmonth < 0 || $tmonth > 12) { $flag = 0; } elseif ($tday < 0 || $tday > 31) { $flag = 0; } else { $tdate = $tyear . "-" . $tmonth . "-" . $tday; if ((time() - mktime(0, 0, 0, $tmonth, $tday, $tyear)) > 18 * 365 * 24 * 60 * 60) { $flag = 0; } else { $flag = 1; } } } } $result['error'] = 2;//0:未知错误,1:身份证格式错误,2:无错误 $result['flag'] = $flag;//0标示成年,1标示未成年 $result['tdate'] = $tdate;//生日日期 return $result; } /**创建可以识别的短链接 */ public function createShortUrl($url, $m_id) { $url = base64_encode($url); $original_url = config('app.url') . "/api/admin/messageUrlGoto?message_id=$m_id&uri=$url"; $urlArray = $this->shortUrl($original_url); if ($urlArray) { if ($urlArray['code'] == 0) { return $urlArray['url']; } else { return $url; } } return $url; } public function createShortUrlv2($url, $m_id) { $url = base64_encode($url); $original_url = env('APP_URL') . "/api/admin/messageUrlGotoV2?message_id=$m_id&uri=$url"; $urlArray = $this->shortUrl($original_url); if ($urlArray) { if ($urlArray['code'] == 0) { return $urlArray['url']; } else { return $url; } } return $url; } public function createShortUrlv3($url, $recive_id) { $url = base64_encode($url); $original_url = env("APP_URL") . "/api/admin/messageUrlGotoV3?&uri=$url&recive_id=$recive_id"; $urlArray = $this->shortUrl($original_url); if ($urlArray) { if ($urlArray['code'] == 0) { return $urlArray['url']; } else { return $url; } } return $url; } /** * 求两个日期之间相差的天数 * (针对1970年1月1日之后,求之前可以采用泰勒公式) * @param string $day1 * @param string $day2 * @return number */ function diffBetweenTwoDays($day1, $day2) { $second1 = strtotime($day1); $second2 = strtotime($day2); if ($second1 < $second2) { $tmp = $second2; $second2 = $second1; $second1 = $tmp; } return intval(($second1 - $second2) / 86400); } /** * 校验日期格式是否合法 * @param string $date * @param array $formats * @return bool */ function isDateValid($date) { $unixTime = strtotime($date); if (!$unixTime) { //无法用strtotime转换,说明日期格式非法 return false; } else { return true; } } /**获取微信链接地址 */ public function getWecharLink($url, $query = null) { //获取微信地址 $app = \WechatService::app()->access_token; $token = $app->getToken(true); $data = []; $data['jump_wxa']['path'] = $url; $data['jump_wxa']['query'] = $query; $data['is_expire'] = true; $data['expire_time'] = time() + 30 * 24 * 60 * 60; $data = json_encode($data); $wechaturl = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=' . $token['access_token']; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_URL, $wechaturl); // curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$" . $wechaturl, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $result = curl_exec($curl); $result = json_decode($result, true); $jump_url = ''; if (array_key_exists('openlink', $result)) { $jump_url = $result['openlink']; } return $jump_url; } public function clickUrl($url, $messgae_id) { $message_url = 'https://love.ufutx.com/api/admin/get/phone?message_id=' . $messgae_id . '&uri=' . $url; return $message_url; } // 'https://love.ufutx.com/h5/#/userDetail/'.$send_user_id; public function shortUrl($url) { $url = base64_encode($url); $original_url = "https://love.ufutx.com/api/admin/messageUrlGoto?uri=$url"; $link = UrlLink::firstOrCreate(['url' => $original_url]); $code = $this->decb64($link->id); $link->update(['short_url' => 'ufutx.cn/s/' . $code]); return ['code' => 0, 'url' => 'ufutx.cn/s/' . $code]; } public function shortUrlv3($url) { $url = urldecode($url); $link = UrlLink::firstOrCreate(['url' => $url]); $code = $this->decb64($link->id); $link->update(['short_url' => 'ufutx.cn/s/' . $code]); return ['code' => 0, 'url' => 'ufutx.cn/s/' . $code]; } /* * php截取指定两个字符之间字符串 * */ function get_between($input, $start, $end) { $substr = substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * (-1)); return $substr; } public function longUrl($code) { $id = $this->b64dec($code); Log::info($id); $link = UrlLink::find($id); Log::info($link->url); if (!empty($link)) { $link->update(['is_click' => 1]); if (strpos($link->url, 'receive_user_id')) { $send_user_id = $this->get_between($link->url, 'userDetail/', '?receive_user_id'); $receive_user_id = substr($link->url, strripos($link->url, "receive_user_id=") + 16); if ($send_user_id && $receive_user_id) { MatchLog::where('receive_user_id', $receive_user_id)->where('send_user_id', $send_user_id) ->update(['status' => 5]); MatchLog::where('receive_user_id', $send_user_id)->where('send_user_id', $receive_user_id) ->update(['status' => 5]); } } return ['code' => 0, 'url' => $link->url]; } return ['code' => 1, 'url' => '']; } public function b64dec($b64) { //64进制转换成10进制 $map = array( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35, 'a' => 36, 'b' => 37, 'c' => 38, 'd' => 39, 'e' => 40, 'f' => 41, 'g' => 42, 'h' => 43, 'i' => 44, 'j' => 45, 'k' => 46, 'l' => 47, 'm' => 48, 'n' => 49, 'o' => 50, 'p' => 51, 'q' => 52, 'r' => 53, 's' => 54, 't' => 55, 'u' => 56, 'v' => 57, 'w' => 58, 'x' => 59, 'y' => 60, 'z' => 61, '_' => 62, '=' => 63 ); $dec = 0; $len = strlen($b64); for ($i = 0; $i < $len; $i++) { $b = $map[$b64[$i]]; if ($b === NULL) { return false; } $j = $len - $i - 1; $dec += ($j == 0 ? $b : (2 << (6 * $j - 1)) * $b); } return $dec; } public function decb64($dec) { //10进制转换成64进制 if ($dec < 0) { return false; } $map = array( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F', 16 => 'G', 17 => 'H', 18 => 'I', 19 => 'J', 20 => 'K', 21 => 'L', 22 => 'M', 23 => 'N', 24 => 'O', 25 => 'P', 26 => 'Q', 27 => 'R', 28 => 'S', 29 => 'T', 30 => 'U', 31 => 'V', 32 => 'W', 33 => 'X', 34 => 'Y', 35 => 'Z', 36 => 'a', 37 => 'b', 38 => 'c', 39 => 'd', 40 => 'e', 41 => 'f', 42 => 'g', 43 => 'h', 44 => 'i', 45 => 'j', 46 => 'k', 47 => 'l', 48 => 'm', 49 => 'n', 50 => 'o', 51 => 'p', 52 => 'q', 53 => 'r', 54 => 's', 55 => 't', 56 => 'u', 57 => 'v', 58 => 'w', 59 => 'x', 60 => 'y', 61 => 'z', 62 => '_', 63 => '=', ); $b64 = ''; do { $b64 = $map[($dec % 64)] . $b64; $dec /= 64; } while ($dec >= 1); return $b64; } /** * 身份证获取性别 * @param [type] $idCard [description] * @return [type] 0:未知,1:男,2:女 */ function getSexByCard($idCard) { $position = (strlen($idCard) == 15 ? -1 : -2); switch (strlen($idCard)) { case 18: $position = -2; break; case 15: $position = -1; break; default: $position = 0; break; } if (empty($position)) return 0; if (((int) substr($idCard, $position, 1)) % 2 == 0) { return 2; } return 1; } //购买成功通知商户 merchant_openid商户openid user_openid 用户openid public function sendBuySuccessNoticeToBusiness($object, $merchant_openid, $type, $price, $mobile, $name) { \Log::info('start send buy success notice to business ' . $type . $merchant_openid); if (!$merchant_openid) return; $text = '有用户下新订单了'; $url = ''; if ($type == 'merchant') { $text = '有用户下新订单了'; $url = env('APP_URL') . '/pu_m/#/home'; } if ($type == 'recommend' || $type == 'first_invitation') { if ($mobile != '未获取') { $mobile = substr_replace($mobile, '****', 3, 4); } if (isset($object->consult_account_id)) { $object->merchant_id = ConsultAccount::where('id', $object->consult_account_id)->value('merchant_id'); } $text = '您推荐的用户已成功下单'; $url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $object->merchant_id . '&url=https%3A%2F%2Flove.ufutx.com%2Fpu%2F%23%2FmyRecommend'; } // 渠道分享 if ($type == 'channel') { if ($mobile != '未获取') { $mobile = substr_replace($mobile, '****', 3, 4); } $text = '有用户通过你分享的渠道二维码下单了'; $url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $object->merchant_id . '&url=https%3A%2F%2Flove.ufutx.com%2Fpu%2F%23%2FmyRecommend'; } $param['touser'] = $merchant_openid; $param['template_id'] = config('wechat.tpls.customer_place_order'); $param['url'] = $url; $param['data'] = [ 'first' => $text, 'keyword1' => $name,//下单账号 'keyword2' => date('Y-m-d H:i:s'),//下单时间 'keyword3' => $object->title,//下单产品 'keyword4' => $price . '元',//下单金额 'keyword5' => $mobile,//联系电话 'remark' => '点击登录查看', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); \Log::info('end send buy success notice to user ' . $type . $merchant_openid); } //小程序购买通知指定用户 public function sendMiniBuySuccessNoticeToUser($goods, $merchant_openid, $type, $price, $mobile, $name) { \Log::info('start send buy success notice to business ' . $type . $merchant_openid); if (!$merchant_openid) return; $text = '福恋小程序有用户下新订单了'; $url = ''; $param['touser'] = $merchant_openid; $param['template_id'] = config('wechat.tpls.customer_place_order'); $param['url'] = $url; $param['data'] = [ 'first' => $text, 'keyword1' => $name,//下单账号 'keyword2' => date('Y-m-d H:i:s'),//下单时间 'keyword3' => $goods,//下单产品 'keyword4' => $price . '元',//下单金额 'keyword5' => $mobile,//联系电话 'remark' => '点击登录查看', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); \Log::info('end send buy success notice to user ' . $type . $merchant_openid); } //购买成功通知用户 public function sendBuySuccessNoticeToUser($object, $openid, $type, $trade_no, $price) { \Log::info('start send buy success notice to user ' . $openid); if (!$openid) return; // $result = TouristOrder::where('trade_no',$trade_no)->first(); // $id = $result->type_id; $goods = $object->title; $time = date('Y-m-d H:i:s'); $merchant_id = $object->merchant_id; $actioveLabel = 0; if ($type == 'consulation') { $merchant_id = ConsultAccount::where('id', $object->consult_account_id)->value('merchant_id'); $actioveLabel = 3; } else if ($type == 'activity') { $actioveLabel = 1; } else if ($type == 'service') { $actioveLabel = 0; } else if ($type == 'course') { $actioveLabel = 2; } else if ($type == 'shop') { $actioveLabel = 4; } else { $actioveLabel = 1; } $url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $merchant_id . '&actioveLabel=' . $actioveLabel . '&url=https%3A%2F%2Flove.ufutx.com%2Fpu%2F%23%2FmySignUp'; if ($type == 'course') { $title = '你购买的课程已解锁'; } elseif ($type == 'activity') {//社群活动 $title = '你已成功报名社群活动'; } elseif ($type == 'service') {//社群服务 $title = '你已成功报名社群服务'; } elseif ($type == 'shop') { $title = '你已成功购买商品'; } elseif ($type == 'evaluate') { $url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $merchant_id . '&actioveLabel=' . $actioveLabel . '&url=https%3A%2F%2Flove.ufutx.com%2Fpu%2F%23%2FmyEvaluate'; $title = '你已成功购买测评'; } else {//咨询服务 $title = '你已成功购买咨询服务'; } $param['url'] = $url; $param['touser'] = $openid; $param['template_id'] = config('wechat.tpls.buy_success_notice'); // $param['url'] = env('APP_URL').'/admin_pro/?#/platformMGT/activityMGT'; $param['data'] = [ 'first' => $title, 'keyword1' => $goods, 'keyword2' => $trade_no, 'keyword3' => $price . '元', 'keyword4' => $time, 'remark' => '感谢您的购买!', ]; return $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); \Log::info('end send buy success notice to user ' . $openid); } //领取优惠券通知 public function reciveCoupon($openid, $name, $goods, $price, $amount, $url) { if (empty($openid)) return; $param['touser'] = $openid; $param['template_id'] = '4FEMlxgFxPyX42QKUXqhemyTIBxXxObpKYn9qW44l5I'; $param['url'] = $url; $param['data'] = [ 'first' => '用户' . $name . '领取了优惠券,剩余数量' . $amount . '张', 'keyword1' => $goods, 'keyword2' => date('Y-m-d H:i:s'), 'keyword3' => 1, 'keyword4' => '0.00元', 'keyword5' => $price . '元', 'remark' => '点击查看', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } //发送模板消息通知 活动审核 public function sendActivityNoticeToUserV2($activity, $user) { // $param['touser'] = 'oPC_2vnSECnYp5p--uaq3rca3Ry0'; //刘晋测试用 $param['touser'] = 'oPC_2vnHCbibl0WAVnyY-8-zJyb8';//张艳彬openid $param['template_id'] = config('wechat.tpls.activity_audited_notice'); $param['url'] = env('APP_URL') . '/admin_pro/?#/platformMGT/activityMGT'; $param['data'] = [ 'first' => '有一个新的活动创建,等待你的审核', 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $activity->theme, 'keyword3' => $user->nickname . '创建了一个新的活动等待审核请您尽快处理。', 'remark' => '活动审核', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } //活动审核通过 public function sendActivityNoticeToUserV3($activity, $user) { $param['touser'] = $user->wechat->openid; $param['template_id'] = config('wechat.tpls.activity_audited_notice'); $param['url'] = env('APP_URL') . '/admin_pro/?#/platformMGT/activityMGT'; $param['data'] = [ 'first' => '您创建的活动审核通过了', 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $activity->theme, 'keyword3' => '点击查看', 'remark' => '活动审核', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } //发送模板消息通知 老师入驻 public function addNewAnchorToUser($user) { //推荐人名字 $recommend_name = '无推荐人'; $from_user_name = Viewer::where('openid', $user->from_openid)->value('nickname'); if (empty($from_user_name)) { if ($user->viewer_id) { $viewer = Viewer::where('id', $user->viewer_id)->first(); if ($viewer && $viewer->viewer_id) { $from_user_name = Viewer::where('id', $viewer->viewer_id)->value('nickname'); } } } $from_user_name = $from_user_name ? $from_user_name : $recommend_name; $openid = [ 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc',//glore 'oPC_2vnajtNMdlw_sbcpuw-aEYKg',//旦齐 'oPC_2viImGPjoPLaytzNdiLAd9Dc',//淑美 'oPC_2vojb_lVO5mxh4p_mqXr7dsI',//小敏 'oPC_2vl7ywsFAjzf-NHZfoyvZloc',//环环 'oPC_2vl0xVIqoa6pynVyJvooH1tQ',//陈彬 ]; foreach ($openid as $value) { $param['touser'] = $value; $param['template_id'] = config('wechat.tpls.activity_audited_notice'); $param['url'] = env('APP_URL') . '/admin_pro/?#/teacherMGT/enterList'; $param['data'] = [ 'first' => '有新的老师入驻,请尽快跟进吧', 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => '推荐人:' . $from_user_name, 'keyword3' => $user->name . '准备入驻福恋,点击处理。', 'remark' => '新的老师入驻', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } } public function ConsultationSuccessNotice($result) { $viewer_id = Anchor::where('id', $result->anchor_id)->value('viewer_id'); $openid = Viewer::where('id', $viewer_id)->value('openid'); $param['touser'] = $openid; $param['template_id'] = config('wechat.tpls.consultation_anchor_notice'); $param['url'] = env('APP_URL') . '/api/official/live/wechat/oauth?url=https%3A%2F%2Flove.ufutx.com%2Fh5%2F%23%2FmyCustomer'; $param['data'] = [ 'first' => '咨询订单通知', 'keyword1' => $result->name, 'keyword2' => date('Y-m-d H:i:s'), 'remark' => '用户购买了咨询服务,请及时处理', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } /** * 咨询订单邀请评价 * @param $openid * @param $url * @param $keyword1 * @param $keyword2 * @param $keyword3 * @return void */ public function consultInviteCommentNotice($openid, $url, $keyword1, $keyword2, $keyword3) { $param['touser'] = $openid; $param['template_id'] = config('wechat.tpls.consultation_anchor_notice'); $param['url'] = $url; $param['data'] = [ 'keyword1' => $keyword1, 'keyword2' => $keyword2, 'keyword3' => $keyword3, ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } /** * 咨询相关通知 通用 * @param $openid * @param $url * @param $keyword1 * @param $keyword2 * @param $keyword3 * @return void */ public function consultCustomNotice($openid, $url, $keyword1, $keyword2, $keyword3) { $param['touser'] = $openid; $param['template_id'] = config('wechat.tpls.consultation_anchor_notice'); $param['url'] = $url; $param['data'] = [ 'keyword1' => $keyword1, 'keyword2' => $keyword2, 'keyword3' => $keyword3, ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } //退款通知 public function refundNotice($order, $price, $type) { $tousers = array(); if ($order && $order->channel != 3 || $order->channel != '福恋小程序') { $user_openid = $order->open_id; } else { $user_openid = MerchantUser::where('id', $order->account_id)->value('openid'); } $merchant_openid = MerchantAccount::where('id', $order->merchant_id)->value('openid') ?: Anchor::where('m_id', $order->merchant_id)->value('openid'); if ($user_openid) $tousers[] = $user_openid; if ($merchant_openid) $tousers[] = $merchant_openid; if (empty($tousers)) return false; foreach ($tousers as $value) { $param['template_id'] = config('wechat.tpls.refund_success_notice'); $param['touser'] = $value; $param['url'] = ''; $param['data'] = [ 'first' => $type . '订单已退款成功,订单号:' . $order->trade_no, 'keyword1' => '¥' . $price, 'keyword2' => '原路退回', 'keyword3' => '1-3个工作日,以实际到账时间为准', 'remark' => '若有疑问请联系商家', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } } //退款通知 public function groupRefundNotice($order, $price, $type) { $tousers = array(); if ($order && ($order->channel != 3 || $order->channel != '福恋小程序')) { $user_openid = $order->open_id; } else { $user_openid = MerchantUser::where('id', $order->account_id)->value('openid'); } if ($user_openid) $tousers[] = $user_openid; if (empty($tousers)) return false; foreach ($tousers as $value) { $param['template_id'] = config('wechat.tpls.refund_success_notice'); $param['touser'] = $value; $param['url'] = ''; $param['data'] = [ 'first' => $type . '订单已退款成功,订单号:' . $order->trade_no, 'keyword1' => '¥' . $price, 'keyword2' => '原路退回', 'keyword3' => '1-3个工作日,以实际到账时间为准', 'remark' => '拼团订单失效,原路退回报名费用', ]; $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } } public function is_subscribe($openid) { if (empty($openid)) { return 0; } $config = [ 'app_id' => config('wechat.official_account.new.app_id'), 'secret' => config('wechat.official_account.new.secret'), 'token' => config('wechat.official_account.new.token'), 'aes_key' => config('wechat.official_account.new.aes_key') ]; $app = Factory::officialAccount($config); $wechatUser = $app->user->get($openid); $result = !empty($wechatUser) && isset($wechatUser['subscribe']); $result = $result ? $wechatUser['subscribe'] : 0; return $result; } //发送消息 public function send($touser, $template_id, $url, $data, $miniprogram = null) { $config = [ 'app_id' => config('wechat.official_account.new.app_id'), 'secret' => config('wechat.official_account.new.secret'), 'token' => config('wechat.official_account.new.token'), 'aes_key' => config('wechat.official_account.new.aes_key') ]; $app = Factory::officialAccount($config); $all_data = [ 'touser' => $touser, 'template_id' => $template_id, 'url' => $url, 'miniprogram' => $miniprogram, 'data' => $data, ]; $result = $app->template_message->send($all_data); if ($result['errcode'] != 0) { \Log::info(json_encode($result)); } if ($result['errcode'] == 0) {//记录模板消息发送成功 $all_data['status'] = 1; $all_data['err_msg'] = null; } else { $all_data['status'] = 0; $all_data['err_msg'] = $result['errmsg']; } $all_data['type'] = 'official'; $this->addTemplateMsgLog($all_data); return true; } public function addTemplateMsgLog($data) { $where = $data['type'] == 'mp' ? ['openid' => $data['touser']] : ['official_openid' => $data['touser']]; $user_id = Wechat::where($where)->value('user_id'); $log = new TemplateMsgLog; $log->user_id = $user_id; $log->openid = $data['touser']; $log->type = $data['type']; $log->template_id = $data['template_id']; $log->status = $data['status']; $log->err_msg = $data['err_msg']; $log->data = json_encode($data); $log->save(); return true; } //比较版本号 public function contrastVersion($version, $other_version) { $version = explode('.', $version); $other_version = explode('.', $other_version); if ($version[0] > $other_version[0]) { return true; } if ($version[0] < $other_version[0]) { return false; } if ($version[0] == $other_version[0]) { if ($version[1] > $other_version[1]) { return true; } if ($version[1] < $other_version[1]) { return false; } if ($version[1] == $other_version[1]) { if ($version[2] > $other_version[2]) { return true; } else { return false; } } } } /** 校验字符串 是否包含非法内容 * 失败: * 4001 - 手机号 * 4002 - 包含铭感词 * 成功 1 - : * Type: 1 :全部 2 敏感词 3 手机号 * Type:*/ public function verifyText($textArray, $type = 1) { try { if (!is_array($textArray)) { HandleLogs::error('校验文本,传入参数不是数组', '系统内容安全校验'); return array('context' => '', 'code' => 1); ; } foreach ($textArray as $text) { if ($type == 1 || $type == 3) { $str_verify_mobile = $text; $str_verify_mobile = str_replace('-', '', $str_verify_mobile); $str_verify_mobile = str_replace(' ', '', $str_verify_mobile); $isMatched = preg_match_all('/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/', $str_verify_mobile, $matches); if ($isMatched) { return array('context' => '', 'type' => 'mobile', 'code' => 4001); } } if ($type == 1 || $type == 2) { $illegality_keyword = BadWord::get(); foreach ($illegality_keyword as $i) { $keyword = $i->content; $r = strstr($text, $keyword); if ($r) { return array('context' => $keyword, 'type' => $i->type, 'code' => 4002); } } } } } catch (\Exception $e) { HandleLogs::error('校验文本异常', '系统内容安全校验', $e); return array('context' => '', 'code' => 1); ; } return array('context' => '', 'code' => 1); ; } /** 校验字符串 是否包含非法内容 传入敏感词库 */ public function verifyTextV2($textArray, $illegality_keyword = [], $type = 1) { foreach ($textArray as $text) { if ($type == 1 || $type == 3) { $str_verify_mobile = $text; $str_verify_mobile = str_replace('-', '', $str_verify_mobile); $str_verify_mobile = str_replace(' ', '', $str_verify_mobile); $is_mobile = preg_match_all('/(1\d{10})/', $str_verify_mobile); if ($is_mobile) { return array('context' => '', 'type' => 'mobile', 'code' => 4001, 'detail_context' => $text); } } if ($type == 1 || $type == 2) { foreach ($illegality_keyword as $i) { $keyword = $i->content; $type = $i->type; $r = strstr($text, $keyword); if ($r) { return array('context' => $keyword, 'type' => $type, 'code' => 4002, 'detail_context' => $text); } } } } return array('context' => '', 'code' => 1, 'type' => '', 'detail_context' => ''); ; } /** 金额格式转换 */ public function moneyFormat($m, $decimals) { try { if ($m == '') { return '0'; } if (is_numeric($m)) { if ($m < 1) { return $m; } return number_format($m, $decimals); } else { return $m; } } catch (\Exception $e) { return $m; } } /** 图片增加参数宽度限制 */ public function pictureLimit($src) { return $src . '?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100/quality,q_90'; } /** 校验敏感词。三种,自定义,微信 阿里云 */ public function checkoutTextArray($arrayContent) { $error = ''; try { if (!is_array($arrayContent)) { $arrayContent[] = $arrayContent; } $cause = '包含敏感词'; $result = $this->verifyText($arrayContent); $error = '1'; if ($result['code'] != 1) { if ($result['type'] == 'mobile') { $cause = '包含手机号'; } else { $c = $result['context']; $t = $result['type']; $cause = "您填写的内容 '$c' 为敏感词汇 ,请重新输入"; } return ['cause' => $cause, 'code' => 1]; } // $result = $this->checkIsRiskyContent($arrayContent[0]); // $error = '2'; // if($result){ // return ['cause'=>'包含敏感词','code'=>1]; // } $result = $this->textContentCecurity($arrayContent); $error = '3'; if ($result) { $c = $result['context']; $t = $result['result']; $cause = "您填写的内容 '$c' 为敏感词汇 ,请重新输入"; return ['cause' => $cause, 'code' => 1]; } return ['cause' => '', 'code' => 0]; } catch (\Exception $e) { HandleLogs::error('统一校验敏感词 异常', '统一校验敏感词' . $error, $e); return ['cause' => '', 'code' => 0]; } return ['cause' => '', 'code' => 0]; } /** 校验敏感词。两种,自定义 阿里云 */ public function checkoutTextArrayV2($arrayContent) { $error = ''; try { if (!is_array($arrayContent)) { $arrayContent[] = $arrayContent; } $cause = '包含敏感词'; $result = $this->verifyText($arrayContent);//自定义敏感词检测 $error = '1'; if ($result['code'] != 1) { if ($result['type'] == 'mobile') { $cause = '包含手机号'; } else { $c = $result['context']; $t = $result['type']; $cause = "您填写的内容 '$c'为敏感词 ,请重新输入"; } return ['cause' => $cause, 'code' => 1]; } // $result = $this->checkIsRiskyContent($arrayContent[0]); // $error = '2'; // if($result){ // return ['cause'=>$cause,'code'=>1]; // } $result = $this->textContentCecurity($arrayContent);//阿里云检测 $error = '2'; if ($result) { $c = $result['context']; $t = $result['result']; $cause = "您填写的内容 '$c'为敏感词 ,请重新输入"; return ['cause' => $cause, 'code' => 1]; } return ['cause' => '', 'code' => 0]; } catch (\Exception $e) { HandleLogs::error('统一校验敏感词 异常', '统一校验敏感词' . $error, $e); return ['cause' => '', 'code' => 0]; } return ['cause' => '', 'code' => 0]; } /** 校验敏感词。三种,自定义,微信 阿里云 */ public function checkoutTextArrayV3($arrayContent) { $error = ''; try { if (!is_array($arrayContent)) { $arrayContent[] = $arrayContent; } $cause = '包含敏感词'; $result = $this->verifyText($arrayContent); $error = '1'; if ($result['code'] != 1) { if ($result['type'] == 'mobile') { $cause = '您填写的内容包含手机号' . $arrayContent; } else { $c = $result['context']; $t = $result['type']; $cause = "您填写的内容包含敏感词汇【'$c'】: ,请重新输入"; } return ['cause' => $cause, 'code' => 1]; } $result = $this->checkIsRiskyContent($arrayContent[0]); $error = '2'; if ($result) { return ['cause' => $cause, 'code' => 1]; } $result = $this->textContentCecurity($arrayContent); $error = '3'; if ($result) { $c = $result['context']; $t = $result['result']; $cause = "您填写的内容 '$c' : 包含敏感词汇 ,请重新输入"; return ['cause' => $cause, 'code' => 1]; } return ['cause' => '', 'code' => 0]; } catch (\Exception $e) { HandleLogs::error('统一校验敏感词 异常', '统一校验敏感词' . $error, $e); return ['cause' => '', 'code' => 0]; } return ['cause' => '', 'code' => 0]; } /** 校验图片。微信,阿里云 */ public function checkoutImg() { } /** 微信验证 获取公众号或小程序access_token 如果存在取缓存 */ public function getWxAccessToken($is_newest = false) { try { $accessToken = ''; $appid = config("wechat.mini_program.app_id"); $secret = config("wechat.mini_program.secret"); $key = 'weapp.' + $appid + '.access.token'; if (Cache::has($key) && $is_newest == false) { return Cache::get($key); } if (empty($accessToken)) { $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + $appid + '&secret=' + $secret; $result = $this->http_request($url); if (isset($result['errcode'])) { HandleLogs::error('access_token 获取失败', '微信内容安全', $result); return ''; } $accessToken = $result['access_token']; $expireTime = $result['expires_in']; Cache::put($key, $accessToken, $expireTime - 60); } return $accessToken; } catch (\Exception $e) { HandleLogs::error('access_token 异常', '微信内容安全', $e); return ''; } } /** 微信验证 验证文本是否是风险内容 * @param string $checkContent */ public function checkIsRiskyContent($checkContent) { $return = false; try { if (!empty($checkContent)) { $access_token = $this->getWxAccessToken(); $url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=$access_token"; $data = json_encode(array('content' => $checkContent), JSON_UNESCAPED_UNICODE); $result = $this->http_request($url, $data); if (isset($result['errcode']) && $result['errcode'] == 87014) { return true; } else { return $this->checkIsRiskyContentForthwithLogin($checkContent); } } return $return; } catch (\Exception $e) { HandleLogs::error('第一次校验内容异常', '微信内容安全', $e); return false; } } //高德地图 -- 关键字搜索 public function aMapSearch($keywords) { $url = 'https://restapi.amap.com/v5/place/text?key=e7cd6d99d7fc6115a8b2bad871a2bd4c&keywords=' . $keywords . '&page_size=15'; $final = $this->http_request($url); if ($final['infocode'] == '10000') { return $final['pois']; } return []; } /** 微信验证 二次验证是否是风险内容 * 处理登录过期的情况 清楚token 重新登录 * @param string $checkContent */ private function checkIsRiskyContentForthwithLogin($checkContent) { $return = false; try { if (!empty($checkContent)) { $access_token = $this->getWxAccessToken(true); $url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=$access_token"; $data = json_encode(array('content' => $checkContent), JSON_UNESCAPED_UNICODE); $result = $this->http_request($url, $data); if (isset($result['errcode']) && $result['errcode'] == 87014) { $return = true; } elseif (isset($result['errcode']) && $result['errcode'] != 0) { $this->HandleLogsAdd(3, '微信检验内容安全存在问题', [], '微信内容安全'); } } return $return; } catch (\Exception $e) { $this->HandleLogsAdd(3, '微信检验内容安全存在异常', [], '微信内容安全'); return false; } return $return; } /** 微信验证 图片验证 */ public function checkImgSecCheck($img) { try { $access_token = $this->getWxAccessToken(); $url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=$access_token"; $obj = new CURLFile(realpath($img)); $obj->setMimeType("image/jpeg"); $file['media'] = $obj; $result = $this->http_request($url, $file); if (isset($result['errcode']) && $result['errcode'] == 87014) { return true; } else if (isset($result['errcode']) && $result['errcode'] != 0) { //出现token 过期 或其他问题。则再次登录 $access_token = $this->getWxAccessToken(true); $url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=$access_token"; $result = $this->http_request($url, $file); if (isset($result['errcode']) && $result['errcode'] == 87014) { return true; } else { HandleLogs::error('校验图片失败', '微信内容安全', $result); return false; } } } catch (\Exception $e) { HandleLogs::error('图片校验 异常', '微信内容安全', $e); return false; } return false; } //HTTP请求(支持HTTP/HTTPS,支持GET/POST) private function http_request($url, $data = null) { try { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $output = curl_exec($curl); curl_close($curl); return json_decode($output, true); } catch (\Exception $e) { HandleLogs::error('HTTP请求 异常', '微信内容安全', $e); return ''; } } /** 发送邮件 */ public function sendMail($message) { SendMail::dispatch($message)->onQueue('error_email'); } /** 创建聊天室 * @param [type] $creator [description] * @param [type] $name [description] * @param [type] $announcement [description] * @return [type] [description] */ public function createChatRoom($creator, $name, $announcement = '', $broadcasturl = '', $ext = [], $queuelevel = 0) { \Log::info('创建聊天室'); try { $im = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET')); $result = $im->chatRoomCreate($creator, $name, $announcement, $broadcasturl, $ext, $queuelevel); if (empty($result) || $result['code'] != 200) {//失败 \Log::info($result); throw new \Exception("创建IM聊天室请求失败", 1); } return $result['chatroom']; } catch (\Exception $e) { $this->getError($e); return false; } } /** 获取福币记录的详细类型 */ public function getCoinLogDetailType($content, $type) { if (strpos($content, '真人认证') !== false) { return $content; } else if (strpos($content, '学历认证') !== false) { return $content; } else if (strpos($content, '分享用户') !== false) { return $content; } else if (strpos($content, '完善个人简介') !== false) { return $content; } else if (strpos($content, '完善兴趣爱好') !== false) { return $content; } else if (strpos($content, '完善择偶标准') !== false) { return $content; } else if (strpos($content, '元旦签到') !== false) { return $content; } else if (strpos($content, '完善认证信息') !== false) { return $content; } else if (strpos($content, '完善个人相册') !== false) { return $content; } else if (strpos($content, '天签到') !== false) { return $content; } else if (strpos($content, '实名认证推广') !== false) { return $content; } else if (strpos($content, '分享真人认证') !== false) { return $content; } else if (strpos($content, '邀请好友注册') !== false) { return $content; } else if (strpos($content, '邀请好友认证') !== false) { return $content; } else { $this->HandleLogsAdd(2, '类型没记录', ['content' => $content], 'getCoinLogDetailType'); if ($type == 'RECHARGE') { return '充值福币'; } else if ($type == 'RECGIFT') { return '礼物收益'; } else if ($type == 'RECMOMENT') { return '动态获赠'; } else if ($type == 'RECSYSTEM') { return '系统赠送'; } } return '系统赠送'; } /** 日志收集 */ public function HandleLogsAdd($code = 1, $remark = '', $data = [], $identifying = '') { HandleLogs::add($code, $remark, $data, $identifying); } //生成用户随机字符串 public function randString($len) { $arr = array( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ); $arrlength = count($arr) - 1; $str = ""; for ($i = 0; $i < $len; $i++) { $str .= $arr[mt_rand(0, $arrlength)]; } return $str; } /** * 坐标转地址 * @return */ public function positionGetAddress($location_longitude, $location_latitude) { //1.经纬度转地址 if (empty($location_longitude) || empty($location_latitude)) { return false; } $localtion = $location_latitude . ',' . $location_longitude; $url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" . $localtion . '&key=P43BZ-QSDCP-BMHDP-V3BTR-3EL45-KOFJL'; $result = json_decode(Http::http($url, [], 'GET'), true); if ($result['status'] == 0) { $address_component = $result['result']['address_component']; if (count($address_component) && isset($address_component['province']) && isset($address_component['city'])) { $result = [ 'province' => $address_component['province'], 'city' => $address_component['city'] ]; return $result; } return false; } return false; } public function tencentFaceid($merchant_id, $name, $card_num, $extra) { try { $secret_id = 'AKIDYw7IG1kNm3CAxa2HPO7fbKrCJEwTnxvu'; $secret_key = '4vY5UijW9btzwiGXlndIuMfneLBpFTUa'; $cred = new Credential($secret_id, $secret_key); // 实例化一个http选项,可选的,没有特殊需求可以跳过 $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 $client = new FaceidClient($cred, "", $clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 $req = new GetEidTokenRequest(); $params = array( "IdCard" => $card_num, "Name" => $name, "MerchantId" => $merchant_id, // "0NSJ2212081323290138", "Extra" => $extra, "Config" => [ "InputType" => "4" ] ); $req->fromJsonString(json_encode($params)); // 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应 $resp = $client->GetEidToken($req); $json = $resp->toJsonString(); return json_decode($json); } catch (TencentCloudSDKException $e) { $this->getError($e); return false; } } public function tencentFaceidRes($token) { try { // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密 // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取 $secret_id = 'AKIDYw7IG1kNm3CAxa2HPO7fbKrCJEwTnxvu'; $secret_key = '4vY5UijW9btzwiGXlndIuMfneLBpFTUa'; $cred = new Credential($secret_id, $secret_key); // 实例化一个http选项,可选的,没有特殊需求可以跳过 $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("faceid.tencentcloudapi.com"); // 实例化一个client选项,可选的,没有特殊需求可以跳过 $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); // 实例化要请求产品的client对象,clientProfile是可选的 $client = new FaceidClient($cred, "", $clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 $req = new GetEidResultRequest(); $params = array( "EidToken" => $token ); $req->fromJsonString(json_encode($params)); // 返回的resp是一个GetEidResultResponse的实例,与请求对象对应 $resp = $client->GetEidResult($req); $json = $resp->toJsonString(); return json_decode($json); } catch (TencentCloudSDKException $e) { $this->getError($e); return false; } } /** * 获取当前毫秒时间戳 * @return mixed|string */ function getMillisecond() { $time = explode(" ", microtime()); $time = $time[1] . ($time[0] * 1000); $time2 = explode(".", $time); $time = $time2 [0]; return $time; } }