diff --git a/Application/Qrcode/Controller/QrCodePromotionController.class.php b/Application/Qrcode/Controller/QrCodePromotionController.class.php index cfef9a52d..50b02fdb8 100644 --- a/Application/Qrcode/Controller/QrCodePromotionController.class.php +++ b/Application/Qrcode/Controller/QrCodePromotionController.class.php @@ -170,14 +170,21 @@ class QrCodePromotionController extends BaseController 'qp_id' => $params['id'], 'admin_id' => $loginer['id'], 'admin_name' => $loginer['account'], - 'h5_link' => "", + 'h5_link' => '', + 'short_link' => '', 'create_time' => time(), 'status' => 0, 'qrcode_img' => $params['img'], ]); if ($id > 0) { - $h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."index.php?s=/Qrcode/Jump/jumpMp/id/{$id}"; - M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save(['h5_link' => $h5Link]); + $h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/index.php?s=/Qrcode/Jump/jumpMp/id/{$id}"; + $expireDate = date('Y-m-d', strtotime("+30 day")); + $shortLink = $this->getShortUrl($h5Link, $expireDate); + + M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([ + 'h5_link' => $h5Link, + 'short_link' => $shortLink + ]); } $this->ajaxReturn(['status' => 1, 'message' => '保存成功!']); @@ -222,4 +229,23 @@ class QrCodePromotionController extends BaseController $this->display(); } + public function getShortUrl($long_url, $expire_date) + { + $url = urlencode($long_url); + $key = "612a01db7889bec5e0d0d2d81f@df6cdda6eb39c505f08848f714b0433e"; + $request_url = "http://api.3w.cn/api.htm?format=json&url={$url}&key={$key}&expireDate={$expire_date}&domain=0"; + $result_str = file_get_contents($request_url); + + $url = ""; + if ($result_str) { + $result_arr = json_decode($result_str, true); + + if ($result_arr && $result_arr['code'] == "0") { + $url = $result_arr['url']; + } + } + + return $url; + } + } \ No newline at end of file diff --git a/Application/Qrcode/View/default/QrCodePromotion/linkLists.html b/Application/Qrcode/View/default/QrCodePromotion/linkLists.html index de12c5523..1a7a9a68d 100644 --- a/Application/Qrcode/View/default/QrCodePromotion/linkLists.html +++ b/Application/Qrcode/View/default/QrCodePromotion/linkLists.html @@ -20,6 +20,7 @@ ID 推广链接地址 + 推广链接短地址 添加人员 添加时间 二维码 @@ -32,6 +33,7 @@ {$record.id} {$record.h5_link} + {$record.short_link} {$record.admin_name} {$record.create_time|date='Y-m-d H:i:s', ###}