setWebsite(__NAMESPACE__); } /** * 首页 */ public function index() { } /** * 创建客服二维码,qt创建二维码太麻烦 */ public function createCustomerQrcode($pmid) { // todo 在qml中,暂时无法获取,以后再改进 $token = Request::input("token"); // token $name = Request::input("name"); // 软件对应的网站名称 $statistics_flag = Request::input("flag"); $product_version = Request::input("version"); // 产品版本 $url = "https://www.qasimblog.com/api/index/toCustomer/" . $pmid . "?" . http_build_query([ "flag" => $statistics_flag, "version" => $product_version, "name" => $name, "token" => $token, ]); $qrCode = new QrCode($url); header('Content-Type: ' . $qrCode->getContentType()); echo $qrCode->writeString(); } /** * 企业微信客服跳转 */ public function toCustomer($pmid) { // 获取产品信息 return response()->redirectTo("https://work.weixin.qq.com/kfid/kfcbcbd9a513832ff76"); } /** * 版本升级检测 */ public function upgrade($osType, $pmid) { $version = Request::input('version'); $agent_mid = Request::input('agent_mid'); if (empty($version)) { return responseMessage(2001, "参数错误,请重试!"); } if (!in_array($osType, ['windows', 'linux', 'android', 'ios'])) { return responseMessage(2002, "参数错误,请重试!"); } //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { return responseMessage(2003, "产品不存在"); } // 获取版本信息 if ($agent_mid) { // 升级代理商版本 $versionInfo = DB::table('product_version', "download_url") ->select("version", "desc") ->where('os_type', $osType) ->where('product_id', $productInfo->id) ->where("version", ">", $version) ->where('agent_mid', $agent_mid) ->where('status', 1) ->where('is_delete', 0) ->orderBy('id', "desc")->first(); if (empty($versionInfo)) { $versionInfo = DB::table('product_version') ->select("version", "desc", "download_url") ->where('os_type', $osType) ->where('product_id', $productInfo->id) ->where("version", ">", $version) ->where('status', 1) ->where('is_delete', 0) ->orderBy('id', "desc")->first(); } } else { $versionInfo = DB::table('product_version') ->select("version", "desc", "download_url") ->where('os_type', $osType) ->where('product_id', $productInfo->id) ->where("version", ">", $version) ->where('status', 1) ->where('is_delete', 0) ->orderBy('id', "desc")->first(); } if ($versionInfo) { return responseMessage(1001, "", $versionInfo); } else { return responseMessage(2004, "当前版本已经是最新版本了!"); } } /** * 软件的安装及操作统计 */ public function statistics($pmid) { $this->isLogin(); //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { return responseMessage(2000, "产品不存在"); } $type = Request::input("type"); $tag = Request::input("tag"); $product_version = Request::input("product_version"); // 产品版本 $windows_uuid = Request::input("windows_uuid"); $os_platform = Request::input("os_platform"); $os_version = Request::input("os_version"); $cpu = Request::input("cpu"); $statistics_flag = Request::input("statistics_flag"); $from = Request::input("from"); if (empty($type)) { return responseMessage(2001, "参数错误!"); } if (empty($os_platform)) { return responseMessage(2002, "参数错误!"); } if (empty($windows_uuid)) { return responseMessage(2003, "参数错误!"); } $data = [ "user_id" => $this->userId, "product_id" => $productInfo->id, "product_version" => $product_version, "type" => $type, // 0 下载 1 安装 2 卸载 3 启动 4 操作 "statistics_flag" => $statistics_flag, // 代理商mid "tag" => $tag, //点击的标签,可以统 "windows_uuid" => $windows_uuid, "os_platform" => $os_platform, //windows,linux,android,ios,mac "os_version" => $os_version, // 系统版本 "cpu" => $cpu, //cpu信息32位,64位 "from" => $from, //refer来源 "ip" => Request::getClientIp(), //IP地址 "year" => date("Y"), "month" => date("m"), "day" => date("d"), 'mid' => Str::random(12), 'created_at' => time(), 'updated_at' => time(), ]; $isSuccess = DB::table("user_use_log")->insert($data); if ($isSuccess) { return responseMessage(1001, ""); } else { return responseMessage(2006, "保存失败"); } } /** * 获取客户端IP地址 * @param int $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 * @param bool $adv 是否进行高级模式获取(有可能被伪装) * @return mixed */ /** * 获取ip * @return mixed */ public function getIp() { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { //优先使用 HTTP_X_FORWARDED_FOR,此值是一个逗号分割的多个IP //注意:我这里没做处理,是因为运维在入口处禁止了伪造请求头,HTTP_X_FORWARDED_FOR是可信的,不能代表所有业务场景 //todo 没有禁止伪造请求头下的特殊处理 $ipStr = $_SERVER["HTTP_X_FORWARDED_FOR"]; $ipArr = explode(',', $ipStr); $client_ip = $ipArr[0] ?? ''; } else { $client_ip = $_SERVER["HTTP_CLIENT_IP"] ?? $_SERVER["REMOTE_ADDR"]; } //过滤无效IP if (filter_var($client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false || filter_var($client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) { return $client_ip; } else { return $_SERVER["REMOTE_ADDR"]; } } }