微信公众开发
准备wechat开发准备lanewechat框架
1.微信公众号弹出自己的页面
(1)接口权限,点击修改,添加域名
网页账号 网页授权获取用户基本信息 无上限 已获得 修改
(2)微信公众平台点击菜单跳转,
$menuList = array(
array('id' => '1', 'pid' => '', 'name' => '开始', 'type' => 'view', 'code' => 'http://域名/xxx.php'),
(3)xxx.php中通过
snsapi_base 不跳授权页面
snsapi_userinfo 跳授权页面
$code = $_GET['code'];
if (!isset($code)) {
$redirect_uri = "http://域名/xxx.php";
\LaneWeChat\Core\WeChatOAuth::getCode($redirect_uri, $state=1, $scope='snsapi_base');
} else {
$token = \LaneWeChat\Core\WeChatOAuth::getAccessTokenAndOpenId($code);
$userinfo = \LaneWeChat\Core\UserManage::getUserInfo($token['openid']);
}
2.微信公众号的分享
(1)公众号设置-功能设置-js接口安全域名
(2)在公众号中显示的页面,引入js文件http://res.wx.qq.com/open/js/jweixin-1.0.0.js
(3)修改jssdk.php-httpGet方法
下载 http://curl.haxx.se/ca/cacert.pem证书
curl_setopt($curl,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');
(4)修改jssdk.php-getAccessToken方法,读取access_token文件
(5)页面中导入jssdk.php
$jssdk = new JSSDK("appid", "appsecret");
$signPackage = $jssdk->GetSignPackage();
<script>
wx.config({
debug: false,
appId: '<?php echo $signPackage["appId"];?>',
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: '<?php echo $signPackage["nonceStr"];?>',
signature: '<?php echo $signPackage["signature"];?>',
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
'onMenuShareAppMessage',
]
});
wx.ready(function () {
wx.checkJsApi({
jsApiList: [
'onMenuShareAppMessage',
]
});
wx.onMenuShareAppMessage({
title: '<?=$course->name?>',
link: '',
desc:'<?=$course->description?>',
imgUrl: '<?=$course->small_pic_url?>',
trigger: function (res) {
//alert('用户点击分享到朋友圈');
},
success: function (res) {
//alert('已分享');
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
//alert('wx.onMenuShareTimeline:fail: '+JSON.stringify(res));
}
});
});
wx.error(function (res) {
//alert('wx.error: '+JSON.stringify(res));
});
准备wechat开发准备lanewechat框架
1.微信公众号弹出自己的页面
(1)接口权限,点击修改,添加域名
网页账号 网页授权获取用户基本信息 无上限 已获得 修改
(2)微信公众平台点击菜单跳转,
$menuList = array(
array('id' => '1', 'pid' => '', 'name' => '开始', 'type' => 'view', 'code' => 'http://域名/xxx.php'),
(3)xxx.php中通过
snsapi_base 不跳授权页面
snsapi_userinfo 跳授权页面
$code = $_GET['code'];
if (!isset($code)) {
$redirect_uri = "http://域名/xxx.php";
\LaneWeChat\Core\WeChatOAuth::getCode($redirect_uri, $state=1, $scope='snsapi_base');
} else {
$token = \LaneWeChat\Core\WeChatOAuth::getAccessTokenAndOpenId($code);
$userinfo = \LaneWeChat\Core\UserManage::getUserInfo($token['openid']);
}
2.微信公众号的分享
(1)公众号设置-功能设置-js接口安全域名
(2)在公众号中显示的页面,引入js文件http://res.wx.qq.com/open/js/jweixin-1.0.0.js
(3)修改jssdk.php-httpGet方法
下载 http://curl.haxx.se/ca/cacert.pem证书
curl_setopt($curl,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');
(4)修改jssdk.php-getAccessToken方法,读取access_token文件
(5)页面中导入jssdk.php
$jssdk = new JSSDK("appid", "appsecret");
$signPackage = $jssdk->GetSignPackage();
<script>
wx.config({
debug: false,
appId: '<?php echo $signPackage["appId"];?>',
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: '<?php echo $signPackage["nonceStr"];?>',
signature: '<?php echo $signPackage["signature"];?>',
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
'onMenuShareAppMessage',
]
});
wx.ready(function () {
wx.checkJsApi({
jsApiList: [
'onMenuShareAppMessage',
]
});
wx.onMenuShareAppMessage({
title: '<?=$course->name?>',
link: '',
desc:'<?=$course->description?>',
imgUrl: '<?=$course->small_pic_url?>',
trigger: function (res) {
//alert('用户点击分享到朋友圈');
},
success: function (res) {
//alert('已分享');
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
//alert('wx.onMenuShareTimeline:fail: '+JSON.stringify(res));
}
});
});
wx.error(function (res) {
//alert('wx.error: '+JSON.stringify(res));
});