Commit 26f4f459 authored by hezhen's avatar hezhen

123

parent fe750bad
<?php
//dezend by http://www.yunlu99.com/
function http_request($url, $data = NULL)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$info = curl_exec($curl);
curl_close($curl);
return $info;
}
function createQr2($image, $path, $_W)
{
$access_token = getAccessToken2();
if (!$access_token) {
return false;
}
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' . $access_token;
$postData = array('path' => $path);
$postData = json_encode($postData);
$response = curlPostTmp($url, $postData);
$content = json_decode($response, true);
if (is_array($content) && isset($content['errcode'])) {
return $content;
}
if (200 < strlen($response)) {
$res = file_put_contents($image, $response);
return true;
}
return false;
}
function getAccessToken2()
{
global $_GPC;
global $_W;
$appid = $_W['account']['key'];
$appsecret = $_W['account']['secret'];
$appidMd5 = md5($appid);
if (!is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
if (is_dir(ATTACHMENT_ROOT . '/' . ('images/longbing_company/' . $_W['uniacid'] . '/'))) {
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
$data = ihttp_get($url);
$data = json_decode($data['content'], true);
if (!isset($data['access_token'])) {
return false;
}
$access_token = $data['access_token'];
file_put_contents(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt', json_encode(array('at' => $access_token, 'time' => time() + 6200)));
return $access_token;
}
}
if (is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
$fileInfo = file_get_contents(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt');
if (!$fileInfo) {
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
$data = ihttp_get($url);
$data = json_decode($data['content'], true);
if (!isset($data['access_token'])) {
return false;
}
$access_token = $data['access_token'];
file_put_contents(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt', json_encode(array('at' => $access_token, 'time' => time() + 6200)));
return $access_token;
}
$fileInfo = json_decode($fileInfo, true);
if ($fileInfo['time'] < time()) {
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
$data = ihttp_get($url);
$data = json_decode($data['content'], true);
if (!isset($data['access_token'])) {
return false;
}
$access_token = $data['access_token'];
file_put_contents(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt', json_encode(array('at' => $access_token, 'time' => time() + 6200)));
return $access_token;
}
return $fileInfo['at'];
}
return false;
}
function curlPostTmp($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
define('ROOT_PATH', IA_ROOT . '/addons/longbing_company/');
is_file(ROOT_PATH . '/inc/we7.php') || exit('Access Denied Longbing');
require_once ROOT_PATH . '/inc/we7.php';
global $_GPC;
global $_W;
$uniacid = $_W['uniacid'];
$to_uid = $_GPC['user_id'];
$goods_id = $_GPC['goodsId'];
$path = $_GPC['path'];
//1:旅游,2租车,3营地
$type = $_GPC['type'];
$userInfo=pdo_get('longbing_company_user',array('id'=>$to_uid,'uniacid'=>$_W['uniacid']));
$destination_folder = '/images' . ('/longbing_company/' . $_W['uniacid']);
if ($userInfo&&$userInfo['platform_userid']){
$image = $destination_folder . '/' . $_W['uniacid'] . '-goods'.$type.'-' . $goods_id . '-' . $to_uid . 'qr.png';
$url = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/' . $image;
}else{
$image2 = $destination_folder . '/' . $_W['uniacid'] . '-goods'.$type.'-' . $goods_id . 'qr.png';
$url = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/' . $image2;
}
if (!strstr($url, 'ttps://')) {
$url = 'https://' . $url;
}
$url = str_replace('ttp://', 'ttps://', $url);
echo json_encode(array('errno' => 0, 'message' => '', 'data' => $url ), JSON_UNESCAPED_UNICODE);
if (function_exists('fastcgi_finish_request')) {
@fastcgi_finish_request();
}
if ($image){
if (file_exists(ATTACHMENT_ROOT . $image)) {
@$size = filesize(ATTACHMENT_ROOT . $image);
if ($size < 51220) {
$path =$path.'?id=' . $goods_id . '&parentUserId=' . $userInfo['platform_userid'];
$res = createQr2(ATTACHMENT_ROOT . $image, $path, $_W);
if (is_array($res) && isset($res['errcode'])) {
$appid = $_W['account']['key'];
$appidMd5 = md5($appid);
if (is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
@unlink(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt');
}
}
}
} else {
$path =$path.'?id=' . $goods_id . '&parentUserId=' . $userInfo['platform_userid'];
$res = createQr2(ATTACHMENT_ROOT . $image, $path, $_W);
if (is_array($res) && isset($res['errcode'])) {
$appid = $_W['account']['key'];
$appidMd5 = md5($appid);
if (is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
unlink(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt');
}
}
}
}
if ($image2){
if (file_exists(ATTACHMENT_ROOT . $image2)) {
@$size = filesize(ATTACHMENT_ROOT . $image2);
if ($size < 51220) {
$path =$path.'?id=' . $goods_id . '&parentUserId=' . $userInfo['platform_userid'];
$res = createQr2(ATTACHMENT_ROOT . $image2, $path, $_W);
if (is_array($res) && isset($res['errcode'])) {
$appid = $_W['account']['key'];
$appidMd5 = md5($appid);
if (is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
@unlink(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt');
}
}
}
} else {
$path =$path.'?id=' . $goods_id . '&parentUserId=' . $userInfo['platform_userid'];
$res = createQr2(ATTACHMENT_ROOT . $image2, $path, $_W);
if (is_array($res) && isset($res['errcode'])) {
$appid = $_W['account']['key'];
$appidMd5 = md5($appid);
if (is_file(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt')) {
unlink(IA_ROOT . '/data/tpl/web/' . $appidMd5 . '.txt');
}
}
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment