-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# v1.0.1 (2016-11-23) | ||
|
||
添加代公众号发起网页授权功能 | ||
添加代公众号发起网页授权功能、代公众号使用JS SDK功能 | ||
|
||
# v1.0.0 (2016-11-23) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* 第三方平台代公众号使用JS SDK样例 | ||
* @author lv_fan2008@sina.com | ||
*/ | ||
|
||
include_once "config.php"; | ||
include_once dirname(dirname(__FILE__)) . "/wx_component/WxComponentService.class.php"; | ||
$cfg_arr = array_values($GLOBALS['wxComponentConfig']); | ||
$wxComponentConfig = $cfg_arr[0]; | ||
|
||
$wxComponentService = new WxComponentService($wxComponentConfig, new FileCache($GLOBALS['cacheDir'])); | ||
$appId = "wx19134b98d4e873a5"; // 改为自己授权过的认证服务号appId | ||
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // 当前URL | ||
$signPackage = $wxComponentService->getJsSign($appId, $url); | ||
?> | ||
|
||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
|
||
<h2> | ||
第三方平台代公众号使用JS SDK样例 | ||
</h2> | ||
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.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 | ||
* | ||
* 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决,如仍未能解决可通过以下渠道反馈: | ||
* 邮箱地址:weixin-open@qq.com | ||
* 邮件主题:【微信JS-SDK反馈】具体问题 | ||
* 邮件内容说明:用简明的语言描述问题所在,并交代清楚遇到该问题的场景,可附上截屏图片,微信团队会尽快处理你的反馈。 | ||
*/ | ||
wx.config({ | ||
debug: true, | ||
appId: '<?php echo $signPackage["appId"];?>', | ||
timestamp: <?php echo $signPackage["timestamp"];?>, | ||
nonceStr: '<?php echo $signPackage["nonceStr"];?>', | ||
signature: '<?php echo $signPackage["signature"];?>', | ||
jsApiList: [ | ||
// 所有要调用的 API 都要加到这个列表中 | ||
'checkJsApi', | ||
'onMenuShareTimeline', | ||
'onMenuShareAppMessage', | ||
'onMenuShareQQ', | ||
'onMenuShareWeibo', | ||
'hideMenuItems', | ||
'showMenuItems', | ||
'hideAllNonBaseMenuItem', | ||
'showAllNonBaseMenuItem', | ||
'translateVoice', | ||
'startRecord', | ||
'stopRecord', | ||
'onRecordEnd', | ||
'playVoice', | ||
'pauseVoice', | ||
'stopVoice', | ||
'uploadVoice', | ||
'downloadVoice', | ||
'chooseImage', | ||
'previewImage', | ||
'uploadImage', | ||
'downloadImage', | ||
'getNetworkType', | ||
'openLocation', | ||
'getLocation', | ||
'hideOptionMenu', | ||
'showOptionMenu', | ||
'closeWindow', | ||
'scanQRCode', | ||
'chooseWXPay', | ||
'openProductSpecificView', | ||
'addCard', | ||
'chooseCard', | ||
'openCard' | ||
] | ||
}); | ||
wx.ready(function () { | ||
// 在这里调用 API | ||
alert("wx js sdk ready"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* 第三方平台代公众号发起网页授权 | ||
* @author lv_fan2008@sina.com | ||
*/ | ||
|
||
include_once "config.php"; | ||
include_once dirname(dirname(__FILE__)) . "/wx_component/WxComponentService.class.php"; | ||
$cfg_arr = array_values($GLOBALS['wxComponentConfig']); | ||
$wxComponentConfig = $cfg_arr[0]; | ||
|
||
$appId = "wxd00b671bf4239248"; // 改为自己授权的认证服务号appId | ||
$wxComponentService = new WxComponentService($wxComponentConfig,new FileCache($GLOBALS['cacheDir'])); | ||
if(isset($_GET['code']) && $_GET['state'] == 'fromoauth'){ | ||
log_ex("component_oauth","get:".print_r($_GET,true)); | ||
print_r($_GET); | ||
$ret = $wxComponentService->getOauthAccessTokenForCode($appId); | ||
log_ex("component_oauth","getOauthAccessTokenForCode ret:".print_r($ret,true)); | ||
if($ret){ | ||
print_r($ret); | ||
$user = $wxComponentService->getOauthUserinfo($ret['access_token'],$ret['openid']); | ||
log_ex("component_oauth","getOauthUserinfo ret:".print_r($user,true)); | ||
print_r($user); | ||
} | ||
exit; | ||
}else{ | ||
$appId = "wxd00b671bf4239248";; // 改为自己授权的认证服务号appId | ||
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | ||
$url_path = substr($url,0,strrpos($url,"/")); | ||
$redirectUrl = $url_path."/component_oauth.php"; | ||
$oauth_url = $wxComponentService->getOauthRedirect($appId,$redirectUrl,"fromoauth","snsapi_userinfo"); | ||
} | ||
|
||
?> | ||
|
||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
|
||
<p> | ||
<a href="<?php echo $oauth_url; ?>" target="_blank">测试代公众号发起网页授权</a> | ||
</p> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters