记录工做备忘javascript
采用TP3.2.3来二开--主要是微信受权登陆、js自定义分享、支付+回调php
1)先在公众号获取相关配置参数,配置公众号的网页受权域名、js接口域名html
// 微信配置参数 'wechat_option' => array( 'appid' => 'w****a769023a', 'appsecret' => 'c****0accc10d19e5f85541b9' ), // 微信支付配置 'WEIXINPAY_CONFIG' => array( 'APPID' => 'wx***5a769023a', 'MCHID' => '1***001', //商户号 'KEY' => 'f****djgfjgyukuyklr', 'APPSECRET' => 'cc*****10d19e5f85541b9', // 'NOTIFY_URL' => 'http://t4.hzrt.cn/member/notify' 'NOTIFY_URL' => 'http://t***t.cn/Api/Weixinpay/notify' //支付回调地址,外网能直接访问(避免继承memberbase控制器) ),
2)受权登陆java
a.先获取codeajax
b.经过code获取access_token、openidjson
c.经过access_token、openid获取用户信息api
if(is_weixin()){ $code = I('get.code'); $wechat_option = C('wechat_option'); $appid = $wechat_option['appid']; $appsecret = $wechat_option['appsecret']; if(empty($code)){ // 获取code $redirect_uri = 'http://t4.hzrt.cn/user/login'; $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; redirect($url); } // 经过code获取access_token,openid $result = json_decode(file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code"), true); $access_token = $result['access_token']; $openid = $result['openid']; // 经过access_token,openid获取用户信息 $userinfo = json_decode(file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}"), true);
// 执行后续本身的操做 $row = $this->users_model->where(array('openid' => $userinfo['openid']))->find();
// 执行后续本身的操做
3)微信js自定义分享微信
a.创建好JSSDK类文件app
b.封装好分享参数并实例化JSSDK函数
c.页面引入接口js文件,配置接口config调用
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> // 引入接口js文件 <script type="text/javascript"> // 接口配置 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 都要加到这个列表中 'onMenuShareTimeline', 'onMenuShareAppMessage' ] }); wx.ready(function () { wx.checkJsApi({ jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ], success: function (res) { // alert(JSON.stringify(res)); } }); // 在这里调用 API wx.onMenuShareTimeline({ title: "{$share['title']}", // 分享标题 link: "{$share['url']}", // 分享连接 imgUrl: "http://{$serverdo}{$share['img_url']}", // 分享图标 success: function () { // 用户确认分享后执行的回调函数 $.ajax({ type : 'post', url : '{:U("portal/member/share_success")}', data : { 'silver_bean' : 10 }, dataType : 'json', success:function(){ } }); }, cancel: function () { // 用户取消分享后执行的回调函数 } });
4)微信公众号调用jsapi支付
2.http://www.cnblogs.com/0201zcr/p/5131602.html
3.http://www.cnblogs.com/txw1958/p/weixin-js-sharetimeline.html
4.http://baijunyao.com/article/78