Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信api几个月前已经修复了“不支持中文转义的json结构”,另外SDK重定义的json_encode函数不支持\n换行符号 #317

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
91 changes: 91 additions & 0 deletions test/js-sdk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

<?php
if(isset($_GET['operation'])&&$_GET['operation']=='getJsConfig')
{
include("wechat/wechat.class.php");
$options = array(
'token'=>'tokenaccesskey', //填写你设定的key
'appid'=>'wxdk1234567890', //填写高级调用功能的app id, 请在微信开发模式后台查询
'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
);
$weObj = new Wechat($options);
$url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$res=$weObj->getJsConfig($url);
exit;
}

?>
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>JS-SDK 签名测试</title>
<link rel="stylesheet" href="/weui/weui.min.css"/>
<style>
body, html { height: 100%; }
body { font-family: -apple-system-font, Helvetica Neue, Helvetica, sans-serif; }
ul { list-style: outside none none; }
.page, body { background-color: #f8f8f8; }
.link { color: #1aad19; }
.page__hd { padding: 40px; }
.page__title { font-size: 20px; font-weight: 400; text-align: center; }
.page__desc { color: #888; font-size: 14px; margin-top: 5px; text-align: center; }
.page__logo { text-align: center; }
.weui-footer { margin: 20px 0;}
</style>
</head>
<body>
<div class="container">
<div class="page msg_warn js_show">
<div class="weui-msg">
<div class="weui-msg__icon-area"><i class="weui-icon-success weui-icon_msg"></i></div>
<div class="weui-msg__text-area">
<h2 class="weui-msg__title">JS-SDK 签名测试</h2>
<p class="weui-msg__desc">wechat-php-sdk</p>
</div>
<div class="weui-msg__opr-area">
<p class="weui-btn-area">
<a href="https://github.com/pkkgu/wechat-php-sdk" class="weui-btn weui-btn_primary">wechat-php-sdk</a>
<!-- a href="javascript:void(0);" class="weui-btn weui-btn_default">云端school</a -->
</p>
</div>
<div class="weui-msg__extra-area">
<div class="weui-footer">
<p class="weui-footer__links">
<a href="javascript:void(0);" class="weui-footer__link">wechat-php-sdk</a>
<!-- a href="javascript:void(0);" class="weui-footer__link">云端school</a -->
</p>
<p class="weui-footer__text">Copyright &copy; 2008-2017</p>
</div>
</div>
</div>
</div>
</div>
<div class="weui-toptips weui-toptips_warn js_tooltips">操作提示</div>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="/weui/weui.min.js"></script>
<script src="?operation=getJsConfig"></script>
<script>
wx.ready(function(){
wx.onMenuShareTimeline({
title: 'wechat-php-sdk 分享测试', // 分享标题
link: window.location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'http://wx.eduhz.com/images/logo.jpg', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
alert('success');
},
cancel: function () {
// 用户取消分享后执行的回调函数
alert('cancel');
}

});
});
wx.error(function(res){
alert(JSON.stringify(res));
});
</script>
</body>
</html>
89 changes: 89 additions & 0 deletions test/oauth2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* 微信oAuth认证
*/
include("../wechat.class.php");
class wxauth {
private $options;
public $openid;
public $wxuser;
public $errcode = 0;
public $errmsg = 'success';

public function __construct($options){
$this->options = $options;
$this->wxoauth();
}

public function wxoauth(){
$scope = 'snsapi_base';
$code = isset($_GET['code'])?$_GET['code']:'';
$options = array(
'token'=>$this->options["token"], //填写你设定的key
'appid'=>$this->options["appid"], //填写高级调用功能的app id
'appsecret'=>$this->options["appsecret"] //填写高级调用功能的密钥
);
$we_obj = new Wechat($options);
//通过code获取用户信息
if($code)
{
$json = $we_obj->getOauthAccessToken(); //通过code获取Access Token
if (!$json)
{
//删除code重新获取授权
parse_str($_SERVER['QUERY_STRING'],$QUERY_STRING);
unset($QUERY_STRING['code']);
unset($QUERY_STRING['state']);
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.http_build_query($QUERY_STRING);
$oauth_url = $we_obj->getOauthRedirect($url,"wxbase",$scope);
header('Location: ' . $oauth_url);
die('获取用户授权失败(errCode:'.$we_obj->errCode.')(errMsg:'.$we_obj->errMsg.')');
}
else
{
$this->openid = $json["openid"];
$userinfo = $we_obj->getUserInfo($this->openid);
if($userinfo)
{
if($userinfo['subscribe']==0)
{
$this->errcode = 43004;
$this->errmsg = '用户未关注公众账号';
return false;
}
$this->wxuser = $userinfo;
}
else
{
$this->errcode = $we_obj->errCode;
$this->errmsg = $we_obj->errMsg;
return false;
}
return $this->openid;
}
}

$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$oauth_url = $we_obj->getOauthRedirect($url,"wxbase",$scope);
header('Location: ' . $oauth_url);
}
}

$options = array(
'token'=>'tokenaccesskey', //填写你设定的key
'appid'=>'wxdk1234567890', //填写高级调用功能的app id, 请在微信开发模式后台查询
'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
);

$auth = new wxauth($options);
$wxuser = $auth->wxuser;
if($wxuser['subscribe']==1)
{
$url='login.php';
}
else
{
$url='messageErr.php';
}
require('temp/'.$url);
exit;
5 changes: 5 additions & 0 deletions test/weui/weui.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/weui/weui.min.js

Large diffs are not rendered by default.

Loading