二维码推广

master
tping 3 years ago
parent 5db39d8cbf
commit 19258b94bf

@ -204,8 +204,7 @@ class QrCodePromotionController extends BaseController
if ($id > 0) { if ($id > 0) {
$uniqueStr = $this->getUniqueStr(); $uniqueStr = $this->getUniqueStr();
$h5Link = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/index.php?s=/Qrcode/Jump/jumpMp/{$uniqueStr}"; $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);
$shortLink = $this->getShortUrl($h5Link, $expireDate);
M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([ M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->save([
'unique_str' => $uniqueStr, 'unique_str' => $uniqueStr,
@ -250,10 +249,12 @@ class QrCodePromotionController extends BaseController
if (!$id) return ; if (!$id) return ;
if (IS_POST) { if (IS_POST) {
// var_dump(json_encode(I('post.img'), JSON_FORCE_OBJECT));die;
M('qrcode_promotion_list', 'tab_')->where([ M('qrcode_promotion_list', 'tab_')->where([
"id" => $id "id" => $id
])->save([ ])->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' => '保存成功!']); $this->ajaxReturn(['status' => 1, 'message' => '保存成功!']);
} }
@ -261,7 +262,9 @@ class QrCodePromotionController extends BaseController
$qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where([ $qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where([
"id" => $id "id" => $id
])->find(); ])->find();
$imgs = json_decode($qrcodePromotionList['qrcode_img'], true);
$this->assign('imgs', $imgs);
$this->assign('id', $id); $this->assign('id', $id);
$this->assign('qp_id', $qrcodePromotionList['qp_id']); $this->assign('qp_id', $qrcodePromotionList['qp_id']);
$this->assign('interval_min', $qrcodePromotionList['interval_min']); $this->assign('interval_min', $qrcodePromotionList['interval_min']);
@ -280,6 +283,7 @@ class QrCodePromotionController extends BaseController
public function linkLists() public function linkLists()
{ {
$this->getShortUrl('https://mg.wmtxkj.com');
$page = I('p', 1); $page = I('p', 1);
$row = I('row', 10); $row = I('row', 10);
$qpId = I('get.id', 0); $qpId = I('get.id', 0);
@ -312,23 +316,67 @@ class QrCodePromotionController extends BaseController
$this->display(); $this->display();
} }
public function getShortUrl($long_url, $expire_date) public function getShortUrl($longUrl)
{ {
$url = urlencode($long_url); $shortUrl = '';
$key = "612a01db7889bec5e0d0d2d81f@df6cdda6eb39c505f08848f714b0433e"; $host = "https://encsholin.market.alicloudapi.com";
$request_url = "http://api.3w.cn/api.htm?format=json&url={$url}&key={$key}&expireDate={$expire_date}&domain=0"; $path = "/shortlink";
$result_str = file_get_contents($request_url); $method = "GET";
$appcode = "783dde1552fa412293c56f9ad875579b";//开通服务后 买家中心-查看AppCode
$url = ""; $headers = array();
if ($result_str) { array_push($headers, "Authorization:APPCODE " . $appcode);
$result_arr = json_decode($result_str, true); $querys = "password=&url={$longUrl}";
$url = $host . $path . "?" . $querys;
if ($result_arr && $result_arr['code'] == "0") {
$url = $result_arr['url']; $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;
} }
} }

@ -94,8 +94,9 @@
} }
var id = $("#qp_id").val(); var id = $("#qp_id").val();
var imgs = $("#form_link_add").serialize(); var data = $("#form_link_add").serialize();
if (!imgs) {
if (!$(".images").val()) {
return layer.msg('二维码不能为空') return layer.msg('二维码不能为空')
} }
@ -103,7 +104,7 @@
url: '{:U("linkAdd")}', url: '{:U("linkAdd")}',
type: 'post', type: 'post',
dataType: 'json', dataType: 'json',
data: imgs, data: data,
success: function(result) { success: function(result) {
if (result.status == 1) { if (result.status == 1) {
layer.msg(result.message) layer.msg(result.message)

@ -16,6 +16,21 @@
<form action="{:U('Promote/linkAdd')}" novalidate="novalidate" method="post" class="base_info" id="form_link_add"> <form action="{:U('Promote/linkAdd')}" novalidate="novalidate" method="post" class="base_info" id="form_link_add">
<table class="table2"> <table class="table2">
<tr>
<input id="qp_id" type="hidden" name="qp_id" value="{$qp_id}">
<td class="l"><span class="req">*</span>推广二维码:</td>
<td class="r">
<span id="img">
<volist name="imgs" id="data" key="k">
<img src="{$data}" width="150px" height="150px"/>
<input class="images" name="img[{$k}]" type="hidden" value="{$data}">
<span class="del" data-id="{$k}" style="border: 1px solid #e6a23c; background: #ea9090; font-size: 20px;font-weight: 600;color: #3f51b5;">删除</span>
</volist>
</span>
<input type="file" id="imgFile"/>
</td>
</tr>
<tr> <tr>
<td class="l"><span class="req">*</span>轮播二维码间隔时间(分钟):</td> <td class="l"><span class="req">*</span>轮播二维码间隔时间(分钟):</td>
<td class="r"> <td class="r">
@ -57,6 +72,7 @@
var src = res.path; var src = res.path;
$('#img').append('<img src=' + src + ' width="150px" height="150px"/>'); $('#img').append('<img src=' + src + ' width="150px" height="150px"/>');
$('#img').append('<input class="images" name="img['+ imgIndex +']" type="hidden" value="'+ src +'">'); $('#img').append('<input class="images" name="img['+ imgIndex +']" type="hidden" value="'+ src +'">');
$('#img').append('<span class="del" data-id=' + imgIndex + ' style="border: 1px solid #e6a23c; background: #ea9090; font-size: 20px;font-weight: 600;color: #3f51b5;">删除</span>');
imgIndex = imgIndex + 1; imgIndex = imgIndex + 1;
// $('#img').html('<img src=' + src + ' width="40%" height="40%"/>') // $('#img').html('<img src=' + src + ' width="40%" height="40%"/>')
@ -77,7 +93,8 @@
click: function() { click: function() {
var imgs = $("#form_link_add").serialize(); var imgs = $("#form_link_add").serialize();
if (!imgs) { console.log(imgs);
if (!$(".images").val()) {
return layer.msg('二维码不能为空') return layer.msg('二维码不能为空')
} }
@ -100,7 +117,14 @@
} }
}) })
$(".del").click(function() {
if (!confirm("确定删除吗?")) return ;
var input = $(this).prev();
var img = input.prev();
input.remove();
img.remove();
$(this).remove();
});
</script> </script>
</block> </block>

Loading…
Cancel
Save