|
|
|
<?php
|
|
|
|
namespace Qrcode\Controller;
|
|
|
|
|
|
|
|
class JumpController extends HomeController
|
|
|
|
{
|
|
|
|
private $secret = "99d5dd03c24a3dbedd7ef176ec5b9a39";
|
|
|
|
private $appid = "wxab40e4470236e599";
|
|
|
|
|
|
|
|
private function getAccessToken()
|
|
|
|
{
|
|
|
|
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appid}&secret={$this->secret}";
|
|
|
|
$r = file_get_contents($url);
|
|
|
|
$ret = json_decode($r, true);
|
|
|
|
|
|
|
|
return $ret['access_token'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURLScheme()
|
|
|
|
{
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
$uniqueStr = I('request.unique_str', '');
|
|
|
|
$url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=".$this->getAccessToken();
|
|
|
|
$data = [
|
|
|
|
'jump_wxa' => [
|
|
|
|
'path' => '/pages/index/index',
|
|
|
|
'query' => "id={$uniqueStr}"
|
|
|
|
],
|
|
|
|
'is_expire' => true,
|
|
|
|
"expire_time" => time() + 86400*21
|
|
|
|
];
|
|
|
|
|
|
|
|
$ret = $this->curl_post($url, json_encode($data));
|
|
|
|
|
|
|
|
echo $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function curl_post($url, $post_data = '', $timeout = 3000)
|
|
|
|
{
|
|
|
|
header("Content-type:text/html;charset=utf-8");
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt ($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt ($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
|
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
$file_contents = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
return $file_contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function jumpMp() {
|
|
|
|
$uniqueStr = I('server.QUERY_STRING');
|
|
|
|
$posStr = 'Qrcode/Jump/jumpMp/';
|
|
|
|
$pos = strpos($uniqueStr, $posStr) + strlen($posStr);
|
|
|
|
$uniqueStr = substr($uniqueStr, $pos, 8);
|
|
|
|
$this->assign("unique_str", $uniqueStr);
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
// MiniTop 二维码推广
|
|
|
|
public function getImgs()
|
|
|
|
{
|
|
|
|
$isHttps = is_https();
|
|
|
|
$backgroundImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/b2.png";
|
|
|
|
$qrCodeImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/qrcode.png";
|
|
|
|
$id = I('request.id', '');
|
|
|
|
if (!$id || $id == 'undefined') {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'id' => $_REQUEST['id'],
|
|
|
|
'status' => 1,
|
|
|
|
'background_img' => $backgroundImg,
|
|
|
|
'qrcode_img' => $qrCodeImg
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// 二维码:
|
|
|
|
$qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where(['unique_str' => $id])->find();
|
|
|
|
if (!$qrcodePromotionList) {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'id' => $_REQUEST['id'],
|
|
|
|
'status' => 1,
|
|
|
|
'background_img' => $backgroundImg,
|
|
|
|
'qrcode_img' => $qrCodeImg
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$qrcode = json_decode($qrcodePromotionList['qrcode_img'], true);
|
|
|
|
$qrcodeCnt = count($qrcode);
|
|
|
|
$intervalMin = $qrcodePromotionList['interval_min'];
|
|
|
|
$elapseMin = floor((time() - $qrcodePromotionList['create_time']) / 60);
|
|
|
|
$imgIndex = 0;
|
|
|
|
if ($intervalMin > 0) {
|
|
|
|
$imgIndex = floor($elapseMin / $intervalMin);
|
|
|
|
$imgIndex = $imgIndex % $qrcodeCnt;
|
|
|
|
}
|
|
|
|
// 背景图
|
|
|
|
$qrcodePromotion = M('qrcode_promotion', 'tab_')->where(['id' => $qrcodePromotionList['qp_id']])->find();
|
|
|
|
|
|
|
|
$qrcode = array_values($qrcode);
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'id' => $_REQUEST['id'],
|
|
|
|
'status' => 1,
|
|
|
|
'background_img' => $qrcodePromotion['background_img'],
|
|
|
|
'qrcode_img' => $qrcode[$imgIndex],
|
|
|
|
'q' => $qrcode
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|