You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7 KiB
PHTML

<?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()
{
$id = I('request.id', 0);
$url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=".$this->getAccessToken();
$data = [
'jump_wxa' => [
'path' => '/pages/index/index',
'query' => "id={$id}"
],
'is_expire' => true,
"expire_time" => time() + 86400
];
$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() {
$id = I('request.id', 0);
$this->assign("id", $id);
$this->display();
}
// MiniTop 二维码推广
public function getImgs()
{
$isHttps = is_https();
$backgroundImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/b.png";
$qrCodeImg = ($isHttps? 'https://': 'http://').$_SERVER['HTTP_HOST']."/Public/Qrcode/images/qrcode.png";
$id = I('request.id', 0);
if (!$id || !is_numeric($id)) {
$this->ajaxReturn([
'status' => 1,
'background_img' => $backgroundImg,
'qrcode_img' => $qrCodeImg
]);
}
// 二维码
$qrcodePromotionList = M('qrcode_promotion_list', 'tab_')->where(['id' => $id])->find();
// 背景图
$qrcodePromotion = M('qrcode_promotion', 'tab_')->where(['id' => $qrcodePromotionList['qp_id']])->find();
$this->ajaxReturn([
'status' => 1,
'background_img' => $qrcodePromotion['background_img'],
'qrcode_img' => $qrcodePromotionList['qrcode_img']
]);
}
}