<?php /** * Created by PhpStorm. * User: apple * Date: 15/8/24 * Time: 下午3:32 */ include 'library/init.inc.php'; $log->record_array($_POST); $response = array('error' => 1, 'msg' => ''); $access_token = get_access_token($config['appid'], $config['appsecret']); $openid = getPOST('openid'); $openid = $db->escape($openid); if ($access_token) { if ($ticket = get_qrcode($openid, $access_token)) { $response['url'] = 'http://wechat.wzcy188.com/facm/api/recommend.php?ticket=' . urlencode($openid); $response['error'] = 0; } else { $response['msg'] = '服务器繁忙,请稍后再次获取'; } } else { $response['msg'] = '获取access_token失败'; } echo json_encode($response); exit;
$get_url_response = json_decode($get_url_response); if ($get_url_response->error == 0) { assign('recommend_url', $get_url_response->url); } else { assign('recommend_url', 'http://' . $_SERVER['HTTP_HOST'] . '/article.php?id=' . $id); } //若是推广,生成关注二维码 $member_id = isset($_SESSION['parent_id']) ? $_SESSION['parent_id'] : 0; if ($member_id > 0) { $get_user_info = 'select * from ' . $db->table('member') . ' where `id`=\'' . $member_id . '\''; $user_info = $db->fetchRow($get_user_info); assign('user_info', $user_info); $img_qrcode = 'upload/recommend/' . $user_info['id'] . '.png'; if ($user_info['expired'] <= time()) { $access_token = get_access_token($config['appid'], $config['appsecret']); $qrcode = get_qrcode($user_info['openid'], $access_token); if ($qrcode) { assign('qrcode', $qrcode); } else { assign('qrcode', false); echo '系统繁忙,请刷新一下'; exit; } $source = $user_info['headimg']; $dest = 'themes/' . $config['themes'] . '/images/qr_bg.jpg'; $img_qrcode = image_merge($source, $dest, $qrcode, $user_info['nickname'], $img_qrcode); } if ($img_qrcode) { assign('qrcode', $img_qrcode); } else { assign('qrcode', '');
/** * 首页 * Created by PhpStorm. * User: apple * Date: 15/8/14 * Time: 下午10:11 */ include 'library/init.inc.php'; $ticket = trim(getGET('ticket')); $account = isset($_SESSION['account']) ? $_SESSION['account'] : ''; if ($ticket) { $openid = base64_decode($ticket); $openid = $db->escape($openid); $get_account = 'select `account` from ' . $db->table('member') . ' where `wx_openid`=\'' . $openid . '\''; $account = $db->fetchOne($get_account); } if (!$account) { die('参数错误'); } //获取用户信息 $get_member_info = 'select * from ' . $db->table('member') . ' where `account`=\'' . $account . '\''; $member_info = $db->fetchRow($get_member_info); assign('member_info', $member_info); $qrcode = null; if ($member_info['wx_openid']) { $access_token = get_access_token($config['appid'], $config['appsecret']); $qrcode = get_qrcode($member_info['wx_openid'], $access_token); } assign('qrcode', $qrcode); $smarty->display('qrcode.phtml');
{ $len = strlen($phone); $phoneWithCode = "+91-"; if ($len > 10) { for ($i = $len - 10; $i < $len; $i++) { $phoneWithCode .= $phone[$i]; } } else { $phoneWithCode .= $phone; } return $phoneWithCode; } $length = strlen($_POST['userID']); $link = 'www.makeadiff.in/volunteer/' . $_POST['userID']; $frame = QRcode::text($link, false, QR_ECLEVEL_L, 4, 0); $qrcode = get_qrcode($frame); $idNumber = (string) $_POST['userID']; $idSixLength = appendZeros($idNumber, $length); //echo $idSixLength; ImageTtfText($im, 13, 0, 15, 343, $black, "fonts/BebasNeue-webfont.ttf", $_POST['Post']); ImageTtfText($im, 15, 0, 48, 382, $black, "fonts/univers.ttf", $phoneNumberAppended); ImageTtfText($im, 15, 0, 48, 410, $black, "fonts/univers.ttf", $_POST['Email']); ImageTtfText($im, 13, 0, 637, 324, $madRed, "fonts/BebasNeue-webfont.ttf", "MAD ID : "); ImageTtfText($im, 13, 0, 682, 324, $madRed, "fonts/BebasNeue-webfont.ttf", $idSixLength); ImageTtfText($im, 15, 0, 48, 432, $black, "fonts/univers.ttf", $link); imagecopyresampled($im, $qrcode, 637, 336, 0, 0, 90, 90, 100, 100); /* Parameters 1. Final Image 2. Sampled Image 3. Start X
/** * 获取用户推广二维码 */ function get_qrcode($openid, $access_token) { global $db; global $log; $get_ticket = 'select `ticket` from ' . $db->table('member') . ' where `openid`=\'' . $openid . '\' and `expired`>' . time(); $ticket = $db->fetchOne($get_ticket); if ($ticket) { $qrcode = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket; $log->record('ticket is avaiable.'); return $qrcode; } $update_user = '******' . $db->table('member') . ' set `scene_id`=0 where `expired`<' . time(); $db->update($update_user); $scene_arr = range(1, 100000); $scene_id = 0; foreach ($scene_arr as $id) { $check_scene_id = 'select count(*) from ' . $db->table('member') . ' where `scene_id`=' . $id . ' and `expired`>' . time(); $log->record($check_scene_id); if (!$db->fetchOne($check_scene_id)) { $scene_id = $id; break; } } //scene_id已满 if ($scene_id == 0) { return false; } //临时二维码申请 $data = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": ' . $scene_id . '}}}'; $response = post('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token, $data, false); $response = json_decode($response); if (isset($response->errcode)) { $log->record('get qrcode fail:' . $response->errcode . ':' . $response->errmsg); $sysconf_data = array('value' => 0); $db->autoUpdate('sysconf', $sysconf_data, '`key`=\'expired\''); return get_qrcode($openid, $access_token); return false; } else { $data = array('scene_id' => $scene_id, 'ticket' => $response->ticket, 'expired' => time() + 1800); $db->autoUpdate('member', $data, '`openid`=\'' . $openid . '\''); $qrcode = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $response->ticket; return $qrcode; } }