public function getSignPackage() { $jsapiTicket = WechatHelper::getJsApiTicket(); $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; }
<?php /** * Author: liasica * CreateTime: 15/8/26 下午9:59 * Filename: index.php * PhpStorm: pengyouquan */ header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); require_once __DIR__ . '/../helper/WechatHelper.php'; $wechat = new WechatHelper(); $openid = $_GET['openid']; $status = false; if ($openid != null) { $status = $wechat->getStatusByOpenid($openid); //while (!$status) //{ // $status = $wechat->getStatusByOpenid($openid); // sleep(1); //} } echo json_encode(array('state' => $status));
<?php /** * Author: liasica * CreateTime: 15/8/26 下午9:21 * Filename: auth.php * PhpStorm: pengyouquan */ require_once '../helper/WechatHelper.php'; $dir = __DIR__ . '/../openids/'; $wechat = new WechatHelper(); $code = $_GET['code']; $userInfo = $wechat->getInfo($code); !is_dir($dir) && @mkdir($dir); file_put_contents($dir . $userInfo->openid . '.json', json_encode($userInfo)); $from_openid = $_GET['from_openid']; $to_openid = $userInfo->openid; if ($to_openid != null) { if ($from_openid != null) { // 插入数据 //$url = '../friend.php?openid=' . $userInfo->openid; $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb6b25160f0aacad7&redirect_uri=http%3A%2F%2Fsite.hiall.com.cn%2Fliasicawechatredirect%2Fdq%2F&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'; $check = $wechat->getStatusByOpenid($userInfo->openid); if ($check) { header('Location: ' . $url); } else { $sql = 'INSERT INTO dq_pyq (from_openid, to_openid, created) VALUES (\'' . $from_openid . '\', \'' . $to_openid . '\', ' . time() . ')'; $s = $wechat->Insert($sql); if ($s) { header('Location: ' . $url); }
<?php /** * Author: liasica * CreateTime: 15/8/28 上午10:24 * Filename: comment.php * PhpStorm: pengyouquan */ header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); require_once __DIR__ . '/../helper/WechatHelper.php'; $wechat = new WechatHelper(); $msg = $_GET['msg']; $name = $_GET['name']; if ($name != null && $msg != null) { if ($wechat->saveComment($name, $msg)) { $wechat->renderJson(array('state' => 200)); } else { $wechat->renderJson(array('state' => 1001, 'message' => '保存失败')); } }
<?php /** * Author: liasica * CreateTime: 15/8/27 上午8:21 * Filename: friend.php * PhpStorm: pengyouquan */ require_once "jssdk/jssdk.php"; require_once "helper/WechatHelper.php"; include 'helper/phpqrcode.php'; $jssdk = new JSSDK("wxc39cc201cd75c1b7", "6302805b8a508b37ae0b9784d6f79460"); $signPackage = $jssdk->GetSignPackage(); $wechat = new WechatHelper(); $userInfo = null; if (isset($_GET['code'])) { $code = $_GET['code']; $userInfo = $wechat->getInfo($code); } //var_dump($_GET['openid']); //exit(); if (isset($_GET['openid'])) { $openid = $_GET['openid']; $userInfo = file_get_contents('openids/' . $openid . '.json'); $userInfo = json_decode($userInfo); } if ($userInfo->openid == null) { header('Location: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb6b25160f0aacad7&redirect_uri=http%3A%2F%2Fsite.hiall.com.cn%2Fliasicawechatredirect%2Fdq%2F&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'); exit('链接失效,请重新打开链接(请勿刷新此页)!'); } $status = $wechat->getStatusByOpenid($userInfo->openid);
<?php /** * Author: liasica * CreateTime: 15/8/27 下午2:54 * Filename: tj.php * PhpStorm: pengyouquan */ header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); require_once __DIR__ . '/../helper/WechatHelper.php'; $wechat = new WechatHelper(); $name = $_GET['name']; $value = $wechat->clickTeacher($name); if ($value) { $wechat->renderJson(array('state' => 200)); } else { $wechat->renderJson(array('state' => '500')); }