static function get_js_sign_pack() { require_once PATH_LIBS . "/wechat/jssdk.php"; $jssdk = new JSSDK(Model_Setting::get("WX_APPID"), Model_Setting::get("WX_APPSECRET")); $signPackage = $jssdk->GetSignPackage(); return $signPackage; }
function _initialize() { $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if ($_GET != null) { $info["openid"] = $_GET["openid"]; cookie('USER_INFO', $info, 3600 * 24 * 365); } $time = date("Y-m-d"); if (D("time")->where(array("time" => $time))->find() != null) { D("time")->where(array("time" => $time))->setInc("no"); } else { D("time")->add(array("time" => $time, "no" => 1)); } $temp = get_config(); $this->assign("con", $temp); // cookie('USER_INFO', array('openid' => 'ooJsMuBae9b3XHJVptSqp1Jr9Tw4'), 3600 * 521); $user = cookie('USER_INFO'); $openid = $user['openid']; vendor('Wx.Jssdk'); $jssdk = new JSSDK($temp["AppId"], $temp["AppSecret"]); $signPackage = $jssdk->GetSignPackage(); $this->assign("signPackage", $signPackage); $one = D("Account")->where(array("openid" => $openid))->find(); if ($one["nickname"] == "" || $one["nickname"] != null) { D("Account")->where(array("openid" => $openid))->save(array("nickname" => $user["nickname"])); } if (empty($openid)) { //$this->redirect("Auth/oauth"); header("Location:" . 'http://mt.magicgell.com/user/openid?redirect=' . $url); } else { } }
public function showVoteAction() { $voteid = I('get.voteid'); $sortby = I('get.sortby'); require_once APP_PATH . "Common/Common/jssdk.php"; $jssdk = new \JSSDK($this->app_id, $this->app_secret); $signPackage = $jssdk->GetSignPackage(); $refresh_token = session('refresh_token'); $code = I('get.code'); if (!$refresh_token) { if (!$code) { $this->redirect('gotoOauth', array('voteid' => $voteid)); } $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->app_id . "&secret=" . $this->app_secret . "&code=" . $code . "&grant_type=authorization_code"; $json_content = file_get_contents($url); $json_obj = json_decode($json_content, true); session(array('name' => 'access_token_id', 'expire' => $json_obj['expires_in'])); session('refresh_token', $json_obj['refresh_token']); } else { $url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" . $this->app_id . "&grant_type=refresh_token&refresh_token=" . $refresh_token; $json_content = file_get_contents($url); $json_obj = json_decode($json_content, true); } $_SESSION['user_id'] = $json_obj['openid']; if (!$_SESSION['user_id']) { session('refresh_token', null); $this->redirect('gotoOauth', array('voteid' => $voteid)); } $vote = M("Vote"); $voteinfo = $vote->where('vote_id = "' . $voteid . '"')->find(); if (!$voteinfo) { $this->error("无此投票", U('vote/index')); } $this->assign('voteinfo', $voteinfo); $piao = M("piao"); $total_piao = $piao->where('vote_id = "' . $voteid . '"')->count(); $this->assign('total_piao', $total_piao); $baoming = M("baoming"); if (!$sortby || $sortby == 'new') { $orderby = 'baoming_date desc'; } else { $orderby = 'total_piao desc'; } $count = $baoming->where('vote_id = "' . $voteid . '"')->count(); $page = new \Think\Page($count, 18); $bmlist = $baoming->where('vote_id = "' . $voteid . '"')->limit($page->firstRow . ',' . $page->listRows)->order($orderby)->select(); $show = $page->show(); $this->assign('page', $show); $this->assign('total_baoming', $count); $this->assign('bmlist', $bmlist); $this->assign('signPackage', $signPackage); $this->assign('sortby', $sortby); $this->display(); }
public function _initialize() { // // $this->assign("header_navigation", $this->header_navigation(C('HEADER_NAVIGATION_ID'))); #网站头部导航 dapeng.chen 2012.12.5 // // //网站底部的导航 // $bottom_navigation = $this->bottom_news(); // $this->assign('bottom_navigation',$bottom_navigation); // // $news_faq=$this->get_news_faq(); // // $this->assign('faq_list',$news_faq); #faq 信息 2012.12.10 dapeng.chen // // // //网站的客服信息 // $this->assign('customer_service',C('CUSTOMER_SERVICE'));//$CUSTOMER_SERVICE defined in /Common/common.php // $this->site_config(); // $this->checkAllowedPages(); // $this->setReferer(); // $islogin=0; // if(!empty($_SESSION['user_id']) AND $_SESSION['user_id']>=1){ #dapeng.chen 是否登陆 // $islogin=1; #已登陆 // $user_info = $this->get_userinfo(); #获取用户信息 // $this->assign('user_info',$user_info); // $this->recently_login_game(); #最近登陆的游戏 // } // $this->system_config(); // $this->assign("islogin",$islogin); #dapeng.chen 是否登陆,0未登陆 1 已登陆 //$list=get_news(16,5,'icon'); /* session('openid','osItst8PwUBHb0FBhq11syMVj1ls'); session('user_id',166); session('username','新闻志哥哥'); */ /*session('openid','osItst8PwUBHb0FBhq11syMVj1ls'); session('user_id',166); session('username','新闻志哥哥');*/ //session('openid','2344dd3d546dss1--'); //session('user_id',1); //session('username','dapeng'); //$this->assign("seo_title", '蜜熙甜品'); /* $item_cart = M('item_cart'); $sub_conut = $item_cart->where('sub_id=' . session('sub.sub_id'))->count(); $this->assign("sub_conut", intval($sub_conut)); */ $jssdk = new JSSDK(C('APPID'), C('SECRET')); $signPackage = $jssdk->GetSignPackage(); $this->assign('signPackage', $signPackage); }
function _initialize() { if ($_GET["xxx"] == "admin") { D("jp")->where("`time` < " . time() . " and (shop_id=19 or shop_id=20)")->delete(); echo D()->getLastSql(); exit; } $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $temp = get_config(); $this->assign("con", $temp); $openid = cookie("openid"); vendor('Wx.Jssdk'); $jssdk = new JSSDK($temp["AppId"], $temp["AppSecret"]); $signPackage = $jssdk->GetSignPackage(); $this->assign("signPackage", $signPackage); if (empty($openid)) { $this->redirect("Auth/oauth"); } else { } }
function _initialize() { $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $temp = get_config(); cookie('USER_INFO', array('openid' => 'ooJsMuBae9b3XHJVptSqp1Jr9Tw4'), 3600 * 521); $user = cookie('USER_INFO'); $openid = $user['openid']; vendor('Wx.Jssdk'); $jssdk = new JSSDK($temp["AppId"], $temp["AppSecret"]); $signPackage = $jssdk->GetSignPackage(); $this->assign("signPackage", $signPackage); // $this->createj($signPackage,$temp); $one = D("Account")->where(array("openid" => $openid))->find(); if ($one["nickname"] == "" || $one["nickname"] != null) { D("Account")->where(array("openid" => $openid))->save(array("nickname" => $user["nickname"])); } if (empty($openid)) { $this->redirect("Auth/oauth"); } }
public function doMobileIndex() { global $_GPC, $_W; $rid = intval($_GPC['id']); if (empty($rid)) { message('参数错误!'); } $reply = pdo_fetch("SELECT * FROM " . tablename($this->tablename) . " WHERE rid = :rid ORDER BY `id` DESC", array(':rid' => $rid)); if (empty($reply)) { message('未找到游戏!'); } $openid = $_W['openid']; //是否关注 $followed = !empty($openid); if ($followed) { $f = pdo_fetch("select follow from " . tablename('mc_mapping_fans') . " where openid=:openid limit 1", array(":openid" => $openid)); $followed = !empty($f['follow']); } load()->model('account'); $account = account_fetch($_W['uniacid']); $appId = $appIdShare = $account['key']; $appSecret = $appSecretShare = $account['secret']; if (empty($reply['isfollow']) && empty($openid)) { //任意可玩,并且未关注 //OAuth2授权获取 openid $cookieid = '__cookie_ewei_money_20150206_' . $rid; if ($_W['account']['level'] != 4) { //不是认证服务号 $set = $this->get_sysset(); if (!empty($set['appid']) && !empty($set['appsecret'])) { $appId = $set['appid']; $appSecret = $set['appsecret']; } else { //如果没有借用,判断是否认证服务号 message('请使用认证服务号进行活动,或借用其他认证服务号权限!'); } if (!empty($set['appid_share']) && !empty($set['appsecret_share'])) { $appIdShare = $set['appid_share']; $appSecretShare = $set['appsecret_share']; } } if (empty($appId) || empty($appSecret)) { message('请到管理后台设置完整的 AppID 和AppSecret !'); } $cookie = json_decode(base64_decode($_COOKIE[$cookieid])); if (!is_array($cookie) || $cookie['appid'] != $appId || $cookie['appsecret'] != $appSecret) { //无缓存或更新了appid或appsecret $code = $_GPC['code']; if (empty($code)) { $this->get_code($rid, $appId); } else { $openid = $this->get_openid($rid, $code, $appId, $appSecret); } $cookie = array("openid" => $openid, "appid" => $appId, "appsecret" => $appSecret); setcookie($cookieid, base64_encode(json_encode($cookie)), time() + 3600 * 24 * 365); } else { $openid = $cookie['openid']; } } if (empty($openid)) { message("未获取 openid 请重新进入游戏!"); } $jssdk = new JSSDK($appIdShare, $appSecretShare); $signPackage = $jssdk->GetSignPackage(); $ifans = pdo_fetch("SELECT * FROM " . tablename($this->tablefans) . " WHERE rid = :rid and from_user = :from_user ", array(':from_user' => $openid, ':rid' => $rid)); $reply['daytimes'] = !empty($ifans) ? $ifans['daytimes'] : $reply['daytimes']; $reply['alltimes'] = !empty($ifans) ? $ifans['alltimes'] : $reply['alltimes']; pdo_query("update " . tablename($this->tablename) . " set view_times=view_times+1 where rid=" . $rid . ""); include $this->template('index'); }
/** * 好产品手机报名页面 */ public function actionGindex() { include_once "../../common/weixinjssdk/JSSDK.php"; $jssdk = new \JSSDK("wx708acc93bd6ad1b0", "d05a63f65046e95d4d41dc7858aa9624"); $signPackage = $jssdk->GetSignPackage(); $this->layout = false; return $this->render('goodh5', ['signPackage' => $signPackage, 'goodproduct_city' => ActivityBase::GOODPRODUCT_CITY]); }
public function buyAction() { //微信分享 $jssdk = new JSSDK("你的appId", "你的appSecret"); $signPackage = $jssdk->GetSignPackage(); $data['appId'] = $signPackage['appId']; $data['nonceStr'] = $signPackage['nonceStr']; $data['timestamp'] = $signPackage['timestamp']; $data['signature'] = $signPackage['signature']; $this->_redis->set('token', json_encode($data)); $diypicture = $this->_session->get('diypicture'); $userShare = $this->_req->getQuery('userShare', 0); $this->getView()->assign("data", $diypicture); $this->getView()->assign("token", json_encode($data)); $this->getView()->assign("userShare", $userShare); $this->getView()->display('index/buy.html'); }
//TODO fetch wechat info $data = getSharedData(); $tr = ''; foreach ($data as $item) { $tr .= '<tr><td>' . $item->openid . '</td><td>' . $item->created . '</td></tr>'; } echo '<table>' . $tr . '</table>'; //end } elseif ($action == 'wechatsign') { //TODO fetch wechat token $url = ''; if (!empty($_GET['url'])) { $url = urldecode($_GET['url']); } $jssdk = new JSSDK(APPID, APPSECRET); $signPackage = $jssdk->GetSignPackage($url); echo json_encode($signPackage); return; //end } elseif ($action == "saveform") { $result = array('result' => '0', 'id' => 0, 'path' => '', 'message' => '提交失败'); $form = array(); $form["name"] = $_POST['name']; $form['phone'] = $_POST['phone']; $form['province'] = $_POST['province']; $form['agency'] = $_POST['agency']; $form['city'] = $_POST['city']; $id = saveForm($form); if (!empty($id)) { $result['result'] = 1; $result['message'] = '提交成功';
public function outputShare($sharedata) { if (!class_exists('JSSDK')) { include dirname(__FILE__) . "/jssdk.php"; } $jssdk_data = new JSSDK("wx92a798c69ae2c8b2", "07dfd943eef04574b261a475b9f24019"); $signPackage_data = $jssdk_data->GetSignPackage(); $url = ''; $shareid = time() . rand(1000, 9999); if (isset($sharedata['url'])) { $url = $sharedata['url']; if (strpos($url, "?") == false) { $url = $url . '?shareid=' . $shareid; } else { $url = $url . '&shareid=' . $shareid; } } else { $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] . '?shareid=' . $shareid; } if (isset($_GET['shareid'])) { $this->shareid = $_GET['shareid']; setcookie('F1DATA_SHAREID', $this->shareid, time() + 86400, "/"); } ?> <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script> /* * 注意: * 1. 所有的JS接口只能在公众号绑定的域名下调用,公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。 * 2. 如果发现在 Android 不能分享自定义内容,请到官网下载最新的包覆盖安装,Android 自定义分享接口需升级至 6.0.2.58 版本及以上。 * 3. 完整 JS-SDK 文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html * * 如有问题请通过以下渠道反馈: * 邮箱地址:weixin-open@qq.com * 邮件主题:【微信JS-SDK反馈】具体问题 * 邮件内容说明:用简明的语言描述问题所在,并交代清楚遇到该问题的场景,可附上截屏图片,微信团队会尽快处理你的反馈。 */ var dataForWeixin={ appId: "", img:'<?php echo $sharedata['img']; ?> ', url:'<?php echo $url; ?> ', title: "<?php echo $sharedata['title']; ?> ", desc: "<?php echo $sharedata['desc']; ?> ", fakeid: "", }; wx.config({ // debug: true, appId: '<?php echo $signPackage_data["appId"]; ?> ', timestamp: <?php echo $signPackage_data["timestamp"]; ?> , nonceStr: '<?php echo $signPackage_data["nonceStr"]; ?> ', signature: '<?php echo $signPackage_data["signature"]; ?> ', jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'onMenuShareTimeline','onMenuShareAppMessage' <?php if (isset($sharedata['extrafunctionname'])) { echo ',' . $sharedata['extrafunctionname']; } ?> ] }); wx.ready(function () { wx.showOptionMenu(); // alert('ee'); // 在这里调用 API wx.onMenuShareTimeline({ title: dataForWeixin.title, // 分享标题 link: dataForWeixin.url, // 分享链接 imgUrl: dataForWeixin.img, // 分享图标 success: function () { $.get('f1data/doshare.php?titleid=<?php echo $this->titleid; ?> &uuid=<?php echo $this->uuid; ?> &shareid=<?php echo $this->shareid; ?> &state=1', function(data){ }); <?php if (isset($sharedata['sharesuccesscode'])) { echo $sharedata['sharesuccesscode']; } ?> }, cancel: function () { $.get('f1data/doshare.php?titleid=<?php echo $this->titleid; ?> &uuid=<?php echo $this->uuid; ?> &shareid=<?php echo $this->shareid; ?> &state=2', function(data){ }); } }); wx.onMenuShareAppMessage({ title: dataForWeixin.title, // 分享标题 desc: dataForWeixin.desc, // 分享描述 link: dataForWeixin.url, // 分享链接 imgUrl: dataForWeixin.img, // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 //alert('efd'); $.get('f1data/doshare.php?titleid=<?php echo $this->titleid; ?> &uuid=<?php echo $this->uuid; ?> &shareid=<?php echo $this->shareid; ?> &state=3', function(data){ }); <?php if (isset($sharedata['sharesuccesscode'])) { echo $sharedata['sharesuccesscode']; } ?> }, cancel: function () { // 用户取消分享后执行的回调函数 $.get('f1data/doshare.php?titleid=<?php echo $this->titleid; ?> &uuid=<?php echo $this->uuid; ?> &shareid=<?php echo $this->shareid; ?> &state=4', function(data){ }); } }); }); </script> <?php }
<?php require_once "jssdk/jssdk.php"; if (array_key_exists("type", $_GET)) { if ($_GET["type"] == "json") { $jssdk = new JSSDK("", ""); $signPackage = $jssdk->GetSignPackage(urldecode($_GET["url"])); $ret = json_encode($signPackage); //echo $_GET['callback'].'('.$ret.')'; echo $ret; } }
public function add() { $uid = $this->_get('wecha_id'); $token = $this->_get('token'); if ($uid == '') { $this->error('您需要关注官方公众号才能进入'); } /* S("fans_".$token."_".$uid,NULL); $fans = $this->fans; if($fans == NULL){ $this->error('您需要完善个人信息才能进入发帖',U('Userinfo/index',array('token'=>$token,'wecha_id'=>$uid,'redirect'=>'Forum/add|wecha_id:'.$uid))); } */ require_once SITE_ROOT . '/' . APP_PATH . "Lib//ORG/WeixinSDK/JSSDK.php"; $jssdk = new JSSDK("wx54a224e2def2d349", "6b66c02c993e1a31fa4219c5dbe4ae4f"); $signPackage = $jssdk->GetSignPackage(); $this->assign('signPackage', $signPackage); $this->display(); }
function detail() { vendor('jssdk'); $jssdk = new \JSSDK(); $signPackage = $jssdk->GetSignPackage(); //dump($signPackage);exit(); $this->assign('signPackage', $signPackage); $map['id'] = I('get.id', 0, 'intval'); $info = M('custom_reply_news')->where($map)->find(); $this->assign('info', $info); M('custom_reply_news')->where($map)->setInc('view_count'); // 增加积分 add_credit('custom_reply', 300); $this->display(); }
<?php /** * 优才网全栈工程师调研组 * 微信号:优才创智 * http://www.ucai.cn */ //appid和secret配置 require 'config.php'; //微信sdk,php生成token和签名 require 'jssdk.php'; //调用sdk生成签名信息 $sdk = new JSSDK(APPID, APPSECRET); $arr = $sdk->GetSignPackage(); ?> <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script> wx.config({ debug: true, appId: '<?php echo $arr["appId"]; ?> ', timestamp: <?php echo $arr["timestamp"]; ?> , nonceStr: '<?php echo $arr["nonceStr"]; ?>
function scan() { ////////////////微信支付插件开始///////////////// require_once "wxpay/js/jssdk.php"; session_start(); $jssdk = new JSSDK($this->wxconfig['appid'], $this->wxconfig['appsecret']); $signPackage = $jssdk->GetSignPackage(); $this->assign('signPackage', $signPackage); $this->display(); }
<?php require_once dirname(__FILE__) . "/libcode/def.php"; $jssdk = new JSSDK(_APPID_, _SECRET_); $signPackage = $jssdk->GetSignPackage(_TICKET_); class JSSDK { private $appId; private $appSecret; public function __construct($appId, $appSecret) { $this->appId = $appId; $this->appSecret = $appSecret; } public function getSignPackage($ticket) { $jsapiTicket = file_get_contents($ticket); // 注意 URL 一定要动态获取,不能 hardcode. $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $timestamp = time(); $nonceStr = $this->createNonceStr(); // 这里参数的顺序要按照 key 值 ASCII 码升序排序 $string = "jsapi_ticket={$jsapiTicket}&noncestr={$nonceStr}×tamp={$timestamp}&url={$url}"; $signature = sha1($string); $signPackage = array("appId" => $this->appId, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string); return $signPackage; } private function createNonceStr($length = 16) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
function exchange_online() { if (!isWeixinBrowser()) { $this->error("很遗憾,该页面仅支持微信客户端!"); } $agent = $_SERVER["HTTP_USER_AGENT"]; $version = (int) substr($agent, strpos($agent, "icroMessenger") + strlen("icroMessenger") + 1, 1); if ($version < 6) { //微信版本判断 $this->error("您的微信版本低于6.0,不支持微信卡券功能!"); } //获取个人中奖信息 $target_id = I('id'); $openId = get_openid(); $token = get_token(); $userInfo = getWeixinUserInfo($openId, $token); $this->assign('userInfo', $userInfo); $map['id'] = $target_id; $Scartch = M('Scratch')->field('use_tips')->where($map)->find(); $this->assign('Scratch', $Scartch); unset($map); $map['openid'] = $openId; $map['token'] = $token; $map['target_id'] = $target_id; $map['prize_id'] = array('gt', 0); $my_prizes = M('sn_code')->where($map)->order('prize_id')->select(); unset($map); $map['addon'] = 'Scratch'; $map['target_id'] = $target_id; $prizes = M('prize')->where($map)->order('sort asc')->select(); $my_prizes_sortbyid = array(); foreach ($prizes as $value) { $my_prizes_sortbyid[$value['id']] = $value; } //dump($my_prizes_sortbyid);exit(); vendor('jssdk'); $jssdk = new \JSSDK(); $signPackage = $jssdk->GetSignPackage(); //dump($signPackage);exit(); $this->assign('signPackage', $signPackage); foreach ($my_prizes as $value) { //card_id $value['card_id'] = $my_prizes_sortbyid[$value['prize_id']]['card_id']; $cardExtPackage = $jssdk->getCardExtPackage($value['card_id']); $value['cardExtPackage'] = $cardExtPackage; $my_prizes_sortbyid[$value['prize_id']]['prizes'][] = $value; } //dump($my_prizes_sortbyid);exit(); $this->assign('my_prizes', $my_prizes_sortbyid); //获取对应图片资源 $model_id = 175; unset($map); $map['target_id'] = $target_id; $map['token'] = $token; $img_res = M(get_table_name($model_id))->where($map)->find(); $this->assign('img_res', $img_res); $this->display(); }
private function initPublic() { $token = get_token(); if (!$token || $token == -1) { return false; } $info = get_token_appinfo($token); if (!$info) { return false; } // 设置公众号管理者信息 if ($info['uid']) { $manager_id = $info['uid']; session('manager_id', $manager_id); } $manager = get_userinfo($manager_id); // 设置版权信息 $this->assign('system_copy_right', empty($manager['copy_right']) ? C('COPYRIGHT') : $manager['copy_right']); $tongji_code = empty($manager['tongji_code']) ? C('TONGJI_CODE') : $manager['tongji_code']; $param = $_GET; $param['publicid'] = $info['id']; $param['m'] = MODULE_NAME; $param['c'] = CONTROLLER_NAME; $param['a'] = ACTION_NAME; $param['uid'] = intval(session('mid')); $tongji_code .= '<script>$.post("' . SITE_URL . '/log.php?' . http_build_query($param) . '");</script>'; $this->assign('tongji_code', $tongji_code); // 公众号接口权限 $config = S('PUBLIC_AUTH_' . $info['type']); if (!$config) { $config = M('public_auth')->getField('name,type_' . intval($info['type']) . ' as val'); S('PUBLIC_AUTH_' . $info['type'], $config, 86400); } C($config); // 公众号接口权限 // 初始化微信JSAPI需要的参数 Vendor('jssdk.jssdk'); $jssdk = new \JSSDK($info['appid'], $info['secret']); $jsapiParams = $jssdk->GetSignPackage(); $this->assign('jsapiParams', $jsapiParams); $this->assign('page_title', $info['public_name']); // 用公众号名作为默认的页面标题 $this->assign('public_info', $info); // 通用公众号信息 return $info; }
function wx_js_sdk() { Vendor('Wxjssdk.JSSDK'); $jssdk = new \JSSDK(Wx_C('wx_appid'), Wx_C('wx_secret')); $signPackage = $jssdk->GetSignPackage(); return $signPackage; }
<?php /* * 74cms WAP * ============================================================================ * 版权所有: 骑士网络,并保留所有权利。 * 网站地址: http://www.74cms.com; * ---------------------------------------------------------------------------- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 * 使用;不允许对程序代码以任何形式任何目的的再发布。 * ============================================================================ */ define('IN_QISHI', true); define('REQUEST_MOBILE', true); require_once QISHI_ROOT_PATH . 'include/jssdk.php'; $jssdk = new JSSDK($_CFG['weixin_appid'], $_CFG['weixin_appsecret'], get_access_token()); $signPackage = $jssdk->GetSignPackage(); $smarty->assign("signPackage", $signPackage);
function chaikai() { // 直接把自己作为授权页面 include 'WxOAuth2.class.php'; $oauth2 = new WxOAuth2(); $v_token = $this->_get('token'); $code = $this->_get('code'); $state = $this->_get('state'); vendor('WxJssdk.jssdk', '', '.php'); $jssdk = new JSSDK("wxb959b9317dd0b640", "41b38fa3cbd209b713dd91764666379e"); // $jsoncallback = $_GET['jsoncallback']; // $url1 = $_GET['url1']; $_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; // $_url_array = parse_url($_url); // $_query_query = convertUrlQuery($_url_array['query']); // foreach ($_query_query as $k => $v) { // if (); // } // 使用正则去掉不需要jssdk编码的参数 // $_url = preg_replace('/&(code(.*))/', '', $_url); $signPackage = $jssdk->GetSignPackage($_url); $this->assign('signpackage', $signPackage); $_url = preg_replace('/&(code(.*))/', '', $_url); $this->assign('url', $_url); // 如果没有授权,就去授权 if (!$state) { $appid = M('wxuser')->where(array('token' => $v_token))->getField('appid'); $oauth2->app_id = $appid; $callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; // $url = $oauth2->get_authorize_url($callback, 'snsapi_base', $v_token); $url = $oauth2->get_authorize_url($callback, 'snsapi_userinfo', $v_token); header('location:' . $url); } else { if ($code) { // 如果用户同意授权 // 根据用户标识来确定app_id $wxuser = M('wxuser')->where(array('token' => $v_token))->find(); // dump($wxuser); $oauth2->app_id = $wxuser['appid']; $oauth2->app_secret = $wxuser['appsecret']; // 确认授权后会,根据返回的code获取token $token_arr = $oauth2->get_access_token($wxuser['appid'], $wxuser['appsecret'], $code); if (!$token_arr) { die; } else { // header('location:' . implode(',', $token_arr)); } $user_info = $oauth2->get_user_info($token_arr['access_token'], $token_arr['openid']); //获取用户信息 // dump($user_info); $user_info['privilege'] = json_encode($user_info['privilege']); // echo $v_token; if ($user_info['openid']) { $user_info['token'] = $v_token; $ir = M('wechat_group_list')->add($user_info); } if ($ir) { // echo '添加到数据库成功'; } else { // echo '添加到数据库失败1'; } $this->assign('openid', $token_arr['openid']); $this->assign('headimgurl', $user_info['headimgurl']); if (!$this->wecha_id) { $this->openid = $this->wecha_id = $token_arr['openid']; $this->assign('reopenid', $this->wecha_id); } $this->assign('is_start', $this->is_start($this->packet_info['id'])); $this->display(); } } }