setWebsite(__NAMESPACE__); } /** * exe安装包下载 * * @param string $pmid * @param string $osPlatform * @return \Illuminate\Http\RedirectResponse|void */ public function download(string $pmid, string $osPlatform = 'windows') { $isSuffix = Str::endsWith($pmid, '.exe'); if($isSuffix){ $pmid = rtrim($pmid,".exe"); } //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { die(); } if (!in_array($osPlatform, ['windows', 'linux', 'android', 'ios'])) { die(); } // 获取下载地址,然后跳转 $versionInfo = DB::table('product_version') ->where('os_type', $osPlatform) ->where('product_id', $productInfo->id) ->where('status', 1) ->where("is_delete", 0) ->first(); if ($versionInfo) { return (new \Illuminate\Http\RedirectResponse($versionInfo->download_url)); } else { die(); } } /** * 压缩包程序 * 下载后的安装包,压缩包程序 * * @param $osPlatform * @param $pmid * @return Application|\Illuminate\Http\RedirectResponse|void */ public function installPackage($osPlatform, $pmid) { //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { Log::error("被攻击了 - 产品不存在" . $pmid); die(); } if (!in_array($osPlatform, ['windows', 'linux', 'android', 'ios'])) { Log::error("被攻击了 - 系统类型不存在" . $osPlatform); die(); } $version = Request::input('version'); $agent_mid = Request::input('agent_mid'); // 获取版本信息 $find = DB::table('product_version') ->select("version", "desc", "download_url", "install_package") ->where('os_type', $osPlatform) ->where('product_id', $productInfo->id) ->where('status', 1) ->where('is_delete', 0) ->orderBy('id', "desc"); if ($agent_mid) { $find->where('agent_mid', $agent_mid); } if ($version) { $find->where("version", ">", $version); } $versionInfo = $find->first(); if ($versionInfo) { return (new \Illuminate\Http\RedirectResponse($versionInfo->install_package)); } else { Log::error("致命错误 - 安装包不存在" . $pmid); // 邮件通知管理员 Mail::queue(new SysErrorNotice(__FUNCTION__ . " 致命错误 - 安装包不存在!" . json_encode($productInfo))); die(); } } /** * 支付页面 * * @param string $code * @return Application|\Illuminate\Contracts\View\Factory|View|void */ public function pay(string $code = "") { if (empty($code)) { // 显示错误页面 return view("home/soft/wechatPay", ['success' => false, 'msg' => '参数错误,请重试! -1']); } $info = Cache::get($code); if (empty($info)) { return view("home/soft/wechatPay", ['success' => false, 'msg' => '二维码已过期,如有问题,请联系官方客服! - 2']); } // 触发,扫描完成机制 Cache::put("pay_scan_" . $code, 1, 2 * 3600); /** * 'agent_mid' => $agent_mid, * 'user_id' => $this->userId, * 'product_type' => $product_type, * 'payType' => $payType, * 'sku' => $sku, * 'product_id' => $productInfo->id, */ if ($this->isAlipayClient()) { return $this->alipay($info, $code); } else { return $this->wechatPay($info, $code); } } /** * 微信支付 */ public function wechatPay($requestData, $code) { $type = $requestData['sku'] ?? 4; // 1 月价格 2 半年价格 3 年 // 获取服务商品详情 $goodsInfo = DB::table('product')->find($requestData['product_id']); if (empty($goodsInfo)) { return view("home/soft/wechatPay", ['success' => false, 'msg' => '该产品可能已删除,请重试!']); } if ($goodsInfo->status == 2) { return view("home/soft/wechatPay", ['success' => false, 'msg' => '对不起,该产品已下架,不能购买!']); } // 获取用户信息 $userInfo = DB::table('user_wechat_official_account')->select("openid")->where('user_id', $requestData['user_id'])->where('is_delete', 0)->first(); if (empty($userInfo)) { return view("home/soft/wechatPay", ['success' => false, 'msg' => '该用户不存在,可能已删除,请重试!']); } // 判断 $orderService = $this->getOrderService($requestData['product_type'], $requestData['user_id']); $orderInfo = $orderService->getOrderInfo($code, ['user_id' => $requestData['user_id'], 'order_status' => 1]); // 判断该订单号,是否已经生成,为了解决支付时连续扫描多次的问题 if (empty($orderInfo)) { $orderInfo = $orderService->create($type, $goodsInfo, $code); if (empty($orderInfo)) { return view("home/soft/wechatPay", ['success' => false, 'msg' => '对不起,订单不存在或者已删除!']); } } $orderNo = $orderInfo['order_no']; $config = config('easywechat.pay.default'); $app = Factory::payment($config); $app->scheme($orderNo); $jssdk = $app->jssdk; // 生成支付二维码 $result = $app->order->unify([ 'trade_type' => 'JSAPI', 'product_id' => $orderNo, 'body' => '订单号:' . $orderNo, 'out_trade_no' => $orderNo, 'total_fee' => $orderInfo['order_amount_total'] * 100, 'openid' => $userInfo->openid, ]); $prepay_id = $result['prepay_id']; $prepayConfig = $jssdk->sdkConfig($prepay_id); $configStr = $this->getOfficialAccountConfig(); return view("home/soft/wechatPay", ['success' => true, 'configStr' => $configStr, 'prepayConfig' => $prepayConfig]); } /** * 获取公众号的配置信息 */ private function getOfficialAccountConfig() { $config = config('easywechat.official_account.default'); $app = Factory::officialAccount($config); return $app->jssdk->buildConfig(['chooseWXPay'], false); } /** * 支付宝支付 */ private function alipay($requestData, $code) { $type = $requestData['sku'] ?? ''; // 1 月价格 2 半年价格 3 年 // 获取服务商品详情 $goodsInfo = DB::table('product')->find($requestData['product_id']); if (empty($goodsInfo)) { return view("home/soft/aliPay", ['success' => false, 'msg' => '该产品可能已删除,请重试!']); } if ($goodsInfo->status == 2) { return view("home/soft/aliPay", ['success' => false, 'msg' => '对不起,该产品已下架,不能购买!']); } $orderService = $this->getOrderService($requestData['product_type'], $requestData['user_id']); $orderInfo = $orderService->getOrderInfo($code, ['user_id' => $requestData['user_id'], 'order_status' => 1]); // 判断该订单号,是否已经生成 为了解决支付时连续扫描多次的问题 if (empty($orderInfo)) { $orderInfo = $orderService->create($type, $goodsInfo, $code); if (empty($orderInfo)) { return view("home/soft/aliPay", ['success' => false, 'msg' => '订单不存在或者已删除!']); } } $order = [ 'out_trade_no' => $orderInfo['order_no'], 'total_amount' => $orderInfo['order_amount_total'], 'subject' => '订单号:' . $orderInfo['order_no'], ]; try { //1. 设置参数(全局只需设置一次) Alipay::setOptions($this->getAlipayOptions()); //2. 发起API调用 $result = Alipay::payment()->wap()->pay($order['subject'], $order['out_trade_no'], $order['total_amount'], "", ""); //网页支付 $responseChecker = new ResponseChecker(); //3. 处理响应或异常 if ($responseChecker->success($result)) { Log::info("调用成功"); Log::info("调用成功" . $result->body); echo $result->body; die(); } else { Log::info("调用失败,原因:"); return view("home/soft/aliPay", ['success' => false, 'msg' => "支付失败,请稍后再试!"]); } } catch (\Exception $e) { Log::info("调用失败," . $e->getMessage()); return view("home/soft/aliPay", ['success' => false, 'msg' => $e->getMessage()]); } } /** * 根据订单号,获取订单服务 * * @param string $productType * @param int $userId * @return ComboOrderService|GoodsOrderService|null */ public function getOrderService(string $productType, int $userId): GoodsOrderService|ComboOrderService|null { if ($productType == 1) { return new GoodsOrderService($userId); } else { return new ComboOrderService($userId); } } /** * 登录框 */ public function login($pmid) { return view("home/soft/login"); } /** * 不是会员的提示信息 */ public function reminder($pmid) { //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { abort(404); } // 根据当前的参数,获取登录信息 $loginToken = new LoginTokenService($this->siteInfo['token_table']); // token 放到了userAgent里面,后期优化 $tokenInfo = $loginToken->findToken(\Illuminate\Support\Facades\Request::userAgent()); $isVip = false; if ($tokenInfo && $tokenInfo->user_id) { $billInfo = $this->getUserBill($productInfo->id, $tokenInfo->user_id); if (isset($billInfo) && $billInfo['validity_type'] != 0) { $isVip = true; } } // 获取图片广告 $ad = DB::table("position_list")->where("group_id", 1)->where('tag', 'no_vip_reminder')->first(); // 商品绑定的广告 return view("home/soft/reminder", ["isLogin" => (bool)$tokenInfo, "isVip" => $isVip, "ad" => $ad]); } /** * 商品套餐信息框 * * @param $pmid * @return Application|\Illuminate\Contracts\View\Factory|View */ public function buy($pmid) { $agentMid = Request::input('agent_mid'); $token = \Illuminate\Support\Facades\Request::userAgent(); if (empty($token)) { return view("home/soft/login"); } //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { abort(404); } // 根据当前的参数,获取登录信息 $loginToken = new LoginTokenService($this->siteInfo['token_table']); // token 放到了userAgent里面,后期优化 $tokenInfo = $loginToken->findToken($token); if ($tokenInfo) { $this->userId = $tokenInfo->user_id; // 获取图片广告 $ad = DB::table("position_list") ->where("group_id", 2) ->where('tag', 'buy_box_top_ad')->first(); // 获取用户信息 $userInfo = DB::table('user')->find($this->userId); unset($userInfo->unionid); $billInfo = $this->getUserBill($productInfo->id, $this->userId); return view("home/soft/buy", ["agentMid" => $agentMid, "token" => $token, "billInfo" => $billInfo, "userInfo" => $userInfo, "productInfo" => $productInfo, 'ad' => $ad]); } else { return view("home/soft/login"); } } //////////////////////////////////////////////////////// //// electron //////////////////////////////////////// //////////////////////////////////////////////////////// public function login2($pmid) { return view("home/soft/electron/login"); } /** * 不是会员的提示信息 */ public function reminder2($pmid) { //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { abort(404); } // 根据当前的参数,获取登录信息 $loginToken = new LoginTokenService($this->siteInfo['token_table']); // token 放到了userAgent里面,后期优化 $tokenInfo = $loginToken->findToken(\Illuminate\Support\Facades\Request::userAgent()); $isVip = false; if ($tokenInfo && $tokenInfo->user_id) { $billInfo = $this->getUserBill($productInfo->id, $tokenInfo->user_id); if (isset($billInfo) && $billInfo['validity_type'] != 0) { $isVip = true; } } // 获取图片广告 $ad = DB::table("position_list")->where("product_id", $productInfo->id)->where('tag', 'no_vip_reminder')->first(); // 商品绑定的广告 return view("home/soft/electron/reminder", ["isLogin" => (bool)$tokenInfo, "isVip" => $isVip, "ad" => $ad]); } /** * 商品套餐信息框 * * @param $pmid * @return Application|\Illuminate\Contracts\View\Factory|View */ public function buy2($pmid) { $agentMid = Request::input('agent_mid'); $token = Request::input('token'); // $token = \Illuminate\Support\Facades\request::header(); // dd($_REQUEST,$_GET,$token, $_COOKIE); if (empty($token)) { return view("home/soft/electron/login"); } //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { abort(404); } // 根据当前的参数,获取登录信息 $loginToken = new LoginTokenService($this->siteInfo['token_table']); // token 放到了userAgent里面,后期优化 $tokenInfo = $loginToken->findToken($token); if ($tokenInfo) { $this->userId = $tokenInfo->user_id; // 获取图片广告 $ad = DB::table("position_list") ->where("product_id", $productInfo->id) ->where('tag', 'buy_box_top_ad')->first(); // 获取用户信息 $userInfo = DB::table('user')->find($this->userId); unset($userInfo->unionid); $billInfo = $this->getUserBill($productInfo->id, $this->userId); return view("home/soft/electron/buy", ["agentMid" => $agentMid, "token" => $token, "billInfo" => $billInfo, "userInfo" => $userInfo, "productInfo" => $productInfo, 'ad' => $ad]); } else { return view("home/soft/electron/login"); } } /** * 获取购买的产品的账单信息 */ private function getUserBill($productId, $userId) { // 获取该产品的支付信息 $validity_type = 0; $validity_end_time = ""; $billInfo = DB::table("user_buy_bill")->where("product_id", $productId)->where("user_id", $userId)->where("is_delete", 0)->first(); if ($billInfo) { if ($billInfo->validity_type == 2) { // 永久有效 $validity_type = 2; } else if ($billInfo->validity_type == 1) { // // 时间有效期 $end_time = $billInfo->validity_end_time; if (time() < $end_time) { $validity_type = 1; $validity_end_time = date('Y-m-d H:i:s', $end_time); } } } return ["validity_type" => $validity_type, "validity_end_time" => $validity_end_time]; } /** * 卸载后,优惠弹窗 */ public function uninstallWeb($pmid) { //判断该产品是否存在 $productInfo = DB::table('product')->where('mid', $pmid)->where('is_delete', 0)->first(); if (empty($productInfo)) { abort(404); } return view("home/soft/login", ['productInfo' => $productInfo]); } }