|
|
|
@ -204,8 +204,7 @@ class QrCodePromotionController extends BaseController
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
$uniqueStr = $this->getUniqueStr();
|
|
|
|
|
$h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/index.php?s=/Qrcode/Jump/jumpMp/{$uniqueStr}";
|
|
|
|
|
$expireDate = date('Y-m-d', strtotime("+30 day"));
|
|
|
|
|
$shortLink = $this->getShortUrl($h5Link, $expireDate);
|
|
|
|
|
$shortLink = $this->getShortUrl($h5Link);
|
|
|
|
|
|
|
|
|
|
M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([
|
|
|
|
|
'unique_str' => $uniqueStr,
|
|
|
|
@ -250,10 +249,12 @@ class QrCodePromotionController extends BaseController
|
|
|
|
|
if (!$id) return ;
|
|
|
|
|
|
|
|
|
|
if (IS_POST) {
|
|
|
|
|
// var_dump(json_encode(I('post.img'), JSON_FORCE_OBJECT));die;
|
|
|
|
|
M('qrcode_promotion_list', 'tab_')->where([
|
|
|
|
|
"id" => $id
|
|
|
|
|
])->save([
|
|
|
|
|
'interval_min' => I('post.interval_min')
|
|
|
|
|
'interval_min' => I('post.interval_min'),
|
|
|
|
|
'qrcode_img' => json_encode(I('post.img'), JSON_FORCE_OBJECT)
|
|
|
|
|
]);
|
|
|
|
|
$this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
|
|
|
|
|
}
|
|
|
|
@ -261,7 +262,9 @@ class QrCodePromotionController extends BaseController
|
|
|
|
|
$qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where([
|
|
|
|
|
"id" => $id
|
|
|
|
|
])->find();
|
|
|
|
|
$imgs = json_decode($qrcodePromotionList['qrcode_img'], true);
|
|
|
|
|
|
|
|
|
|
$this->assign('imgs', $imgs);
|
|
|
|
|
$this->assign('id', $id);
|
|
|
|
|
$this->assign('qp_id', $qrcodePromotionList['qp_id']);
|
|
|
|
|
$this->assign('interval_min', $qrcodePromotionList['interval_min']);
|
|
|
|
@ -280,6 +283,7 @@ class QrCodePromotionController extends BaseController
|
|
|
|
|
|
|
|
|
|
public function linkLists()
|
|
|
|
|
{
|
|
|
|
|
$this->getShortUrl('https://mg.wmtxkj.com');
|
|
|
|
|
$page = I('p', 1);
|
|
|
|
|
$row = I('row', 10);
|
|
|
|
|
$qpId = I('get.id', 0);
|
|
|
|
@ -312,23 +316,67 @@ class QrCodePromotionController extends BaseController
|
|
|
|
|
$this->display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getShortUrl($long_url, $expire_date)
|
|
|
|
|
public function getShortUrl($longUrl)
|
|
|
|
|
{
|
|
|
|
|
$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'];
|
|
|
|
|
$shortUrl = '';
|
|
|
|
|
$host = "https://encsholin.market.alicloudapi.com";
|
|
|
|
|
$path = "/shortlink";
|
|
|
|
|
$method = "GET";
|
|
|
|
|
$appcode = "783dde1552fa412293c56f9ad875579b";//开通服务后 买家中心-查看AppCode
|
|
|
|
|
$headers = array();
|
|
|
|
|
array_push($headers, "Authorization:APPCODE " . $appcode);
|
|
|
|
|
$querys = "password=&url={$longUrl}";
|
|
|
|
|
$url = $host . $path . "?" . $querys;
|
|
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
|
|
|
|
if (1 == strpos("$" . $host, "https://")) {
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
}
|
|
|
|
|
$out_put = curl_exec($curl);
|
|
|
|
|
|
|
|
|
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
|
|
|
|
list($header, $body) = explode("\r\n\r\n", $out_put, 2);
|
|
|
|
|
if ($httpCode == 200) {
|
|
|
|
|
$url = json_decode($body, true);
|
|
|
|
|
$shortUrl = $url['url'];
|
|
|
|
|
if (!$shortUrl) $shortUrl = $url['msg'];
|
|
|
|
|
} else {
|
|
|
|
|
if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) {
|
|
|
|
|
$shortUrl = ("参数错误");
|
|
|
|
|
} elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) {
|
|
|
|
|
$shortUrl = ("AppCode错误");
|
|
|
|
|
} elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) {
|
|
|
|
|
$shortUrl = ("请求的 Method、Path 或者环境错误");
|
|
|
|
|
} elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) {
|
|
|
|
|
$shortUrl = ("服务未被授权(或URL和Path不正确)");
|
|
|
|
|
} elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) {
|
|
|
|
|
$shortUrl = ("套餐包次数用完");
|
|
|
|
|
} elseif ($httpCode == 500) {
|
|
|
|
|
$shortUrl = ("API网关错误");
|
|
|
|
|
} elseif ($httpCode == 0) {
|
|
|
|
|
$shortUrl = ("URL错误");
|
|
|
|
|
} else {
|
|
|
|
|
$shortUrl .= ("参数名错误 或 其他错误");
|
|
|
|
|
$shortUrl .= ($httpCode);
|
|
|
|
|
$headers = explode("\r\n", $header);
|
|
|
|
|
$headList = array();
|
|
|
|
|
foreach ($headers as $head) {
|
|
|
|
|
$value = explode(':', $head);
|
|
|
|
|
$headList[$value[0]] = $value[1];
|
|
|
|
|
}
|
|
|
|
|
$shortUrl .= ($headList['x-ca-error-message']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
return $shortUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|