require dirname(__FILE__) . '/api.class.php'; require dirname(__FILE__) . '/wechat.class.php'; $weixinconfig = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1"); //多微信帐号支持 $id = intval($_GET['id']); if ($id > 0) { $otherconfig = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = {$id}"); if ($otherconfig) { $weixinconfig['token'] = $otherconfig['token']; $weixinconfig['appid'] = $otherconfig['appid']; $weixinconfig['appsecret'] = $otherconfig['appsecret']; } } $baseurl = $weburl = $_SERVER['SERVER_NAME'] ? "http://" . $_SERVER['SERVER_NAME'] . "/" : "http://" . $_SERVER['HTTP_HOST'] . "/"; //$weburl .= $weixinconfig['wap_url'] ? $weixinconfig['wap_url'] : ""; $weixin = new core_lib_wechat($weixinconfig); $weixin->valid(); $api = new weixinapi(); $weburl .= $api->dir; $type = $weixin->getRev()->getRevType(); $wxid = $weixin->getRev()->getRevFrom(); //上报地理信息 $loc = $weixin->getRev()->getUserLocation(); if ($loc) { $api->updatelocation($wxid, $loc); } $reMsg = ""; switch ($type) { case 'text': $content = $weixin->getRev()->getRevContent(); break;
<?php require dirname(__FILE__) . '/api.class.php'; require dirname(__FILE__) . '/wechat.class.php'; $baseurl = $_SERVER['SERVER_NAME'] ? "http://" . $_SERVER['SERVER_NAME'] . "/" : "http://" . $_SERVER['HTTP_HOST'] . "/"; $t = time(); $type = intval($_GET['type']); $rs = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_corn') . " WHERE `issend` = 0 and `sendtype`={$type} order by sendtime desc"); if ($rs) { $weixinconfig = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1"); $weixin = new core_lib_wechat($weixinconfig); $content = unserialize($rs['content']); $msg = array(); $msg['msgtype'] = $content['msgtype']; if ($content['msgtype'] == 'news') { foreach ($content['news']['articles'] as $k => $v) { $msg['news']['articles'][$k]['title'] = $v['title']; $msg['news']['articles'][$k]['description'] = $v['description']; $msg['news']['articles'][$k]['url'] = $baseurl . "mobile/article.php?id=" . $v['article_id']; $msg['news']['articles'][$k]['picurl'] = strpos($v['file_url'], 'http://') == false ? $baseurl . $v['file_url'] : $v['file_url']; } } else { $msg = $content; } if ($type == 1) { $user = $db->getAll("SELECT fake_id FROM " . $GLOBALS['ecs']->table('weixin_user') . " WHERE isfollow=1 and access_token!='' and expire_in>'{$t}' order by expire_in desc"); } else { $user = array(array('fake_id' => $content['touser'])); } if ($user) { foreach ($user as $u) {
require dirname(__FILE__) . '/api.class.php'; require dirname(__FILE__) . '/wechat.class.php'; //多微信帐号支持 $weixinconfig = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1"); //多微信帐号支持 $id = intval($_GET['id']); $oid = intval($_GET['oid']); if ($id > 0) { $otherconfig = $db->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = {$id}"); if ($otherconfig) { $weixinconfig['token'] = $otherconfig['token']; $weixinconfig['appid'] = $otherconfig['appid']; $weixinconfig['appsecret'] = $otherconfig['appsecret']; } } $weixin = new core_lib_wechat($weixinconfig); if ($_GET['code']) { $json = $weixin->getOauthAccessToken(); if ($json['openid']) { $ecuid = $GLOBALS['db']->getOne("select ecuid from " . $GLOBALS['ecs']->table('weixin_user') . " where fake_id='{$json['openid']}'"); if ($ecuid > 0) { $username = $GLOBALS['db']->getOne("select user_name from " . $GLOBALS['ecs']->table('users') . " where user_id='{$ecuid}'"); $GLOBALS['user']->set_session($username); $GLOBALS['user']->set_cookie($username, 1); update_user_info(); //更新用户信息 recalculate_price(); //重新计算购物车中的商品价格 } } $url = $api->dir . "/mobile/user.php";
function update_menu($id = 1) { require '../weixin/wechat.class.php'; $config = $GLOBALS['db']->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = {$id}"); $weixin = new core_lib_wechat($config); $ret = $GLOBALS['db']->getAll("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_menu') . " where pid=0 order by `order` desc"); if ($ret) { foreach ($ret as $k => $v) { $button[$k]['name'] = $v['name']; $ret2 = $GLOBALS['db']->getAll("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_menu') . " where pid={$v['id']} order by `order` desc"); if ($ret2) { foreach ($ret2 as $kk => $vv) { $button[$k]['sub_button'][$kk]['name'] = $vv['name']; if ($vv['type'] == 1) { $button[$k]['sub_button'][$kk]['key'] = $vv['value']; $button[$k]['sub_button'][$kk]['type'] = "click"; } elseif ($vv['type'] == 3) { $button[$k]['sub_button'][$kk]['key'] = $vv['value']; $button[$k]['sub_button'][$kk]['type'] = "click"; } else { $vv['value'] = str_replace('{id}', $id, $vv['value']); $button[$k]['sub_button'][$kk]['url'] = $vv['value']; $button[$k]['sub_button'][$kk]['type'] = "view"; } } } else { if ($v['type'] == 1) { $button[$k]['key'] = $v['value']; $button[$k]['type'] = "click"; } else { $v['value'] = str_replace('{id}', $id, $v['value']); $button[$k]['url'] = $v['value']; $button[$k]['type'] = "view"; } } } } $res = $weixin->createMenu(array('button' => $button)); if ($res === false) { sys_msg('更新菜单出错:' . $weixin->errMsg, 1, $link); } else { return true; } }
$num = $GLOBALS['db']->query($sql); if ($num > 0) { Header("Location: v_shop.php?user_id=" . $user_id); exit; } else { show_message('绑定出错!'); } } } } } //是否生成过二维码 if (is_erweima($user_id) == 0) { require 'weixin/wechat.class.php'; $config = $GLOBALS['db']->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1"); $weixin = new core_lib_wechat($config); $scene_id = $db->getOne("select id from " . $GLOBALS['ecs']->table('weixin_qcode') . " order by id desc"); $scene_id = $scene_id ? $scene_id + 1 : 1; $qcode = $weixin->getQRCode($scene_id, 1, $user_id); $GLOBALS['db']->query("insert into " . $GLOBALS['ecs']->table('weixin_qcode') . " (`id`,`type`,`content`,`qcode`) value ({$scene_id},4,'{$user_id}','{$qcode['ticket']}')"); } if (!$smarty->is_cached('v_user_haibao.dwt', $cache_id)) { assign_template(); $position = assign_ur_here(); $smarty->assign('page_title', $position['title']); // 页面标题 $smarty->assign('ur_here', $position['ur_here']); // 当前位置 /* meta information */ $smarty->assign('keywords', htmlspecialchars($_CFG['shop_keywords'])); $smarty->assign('description', htmlspecialchars($_CFG['shop_desc']));
$state = 0; } if ($_GET['ajax'] == 1) { echo json_encode(array('state' => $state, 'url' => "../user.php")); } else { echo "<script>function myrefresh(){ {$str} }\n\t\tsetTimeout('myrefresh()',1000);</script>"; } exit; } } else { //print_r($_SESSION); //生成登录二维码代码 开始 if ($_SESSION['login_value'] && $_SESSION['_outtime'] > time()) { $token = $GLOBALS['db']->getOne("SELECT token FROM " . $GLOBALS['ecs']->table('weixin_login') . " WHERE `value` = '{$_SESSION['login_value']}'"); } else { $weixinconfig = $GLOBALS['db']->getRow("SELECT * FROM " . $GLOBALS['ecs']->table('weixin_config') . " WHERE `id` = 1"); $weixin = new core_lib_wechat($weixinconfig); $scene_id = $t . rand(1000, 9999); $scene_id = substr($scene_id, 5); $token = $weixin->getQRCode($scene_id, 0, 600); $token = $token['ticket']; $ip = real_ip(); $GLOBALS['db']->query("INSERT INTO " . $GLOBALS['ecs']->table('weixin_login') . " (`createtime`,`token`,`ip`,`value`) value\n\t\t ('{$t}','{$token}','{$ip}','{$scene_id}')"); $_SESSION['login_value'] = $scene_id; $_SESSION['_outtime'] = $t + 600; } //生成登录二维码代码 结束 echo "<h1>请使用微信扫描下面的二维码进行登陆。二维码有效期10分钟。过期请刷新页面重新获取。</h1>"; echo "<p><img src='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={$token}' height='300px'></p>"; echo "<iframe src='login.php?act=check' style='display:none'></iframe>"; }