微信JS-SDK自定義分享功能實(shí)例詳解【分享給朋友/分享到朋友圈】
本文實(shí)例講述了微信JS-SDK自定義分享功能。分享給大家供大家參考,具體如下:
分享出去的內(nèi)容,可以通過jssdk進(jìn)行修改。
1.配置jssdk
Wx_config.html
<?php import("@.ORG.jssdk"); $jssdk = new JSSDK(C('oauth_config.appid'), C('oauth_config.appsecret')); $signPackage = $jssdk->GetSignPackage(); ?>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <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: [ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'chooseImage', 'uploadImage' ] }); </script>
2.加入分享給朋友,分享到朋友圈事件
<script> // 微信JSSDK開發(fā) wx.ready(function () { // 分享給朋友 wx.onMenuShareAppMessage({ title: '{sh:$wxShare.title}', // 商品名 desc: '{sh:$wxShare.desc}', // 店鋪名 link: '{sh:$wxShare.link}', // 商品購買地址 imgUrl: '{sh:$wxShare.imgUrl}', // 分享的圖標(biāo) fail: function (res) { alert(JSON.stringify(res)); } }); // 分享到朋友圈 wx.onMenuShareTimeline({ title: '{sh:$wxShare.title}', // 商品名 link: '{sh:$wxShare.link}', // 商品購買地址 imgUrl: '{sh:$wxShare.imgUrl}', // 分享的圖標(biāo) fail: function (res) { alert(JSON.stringify(res)); } }); }); </script>
3.后臺(tái)獲取wxShare數(shù)據(jù)
/**** 獲取微信分享數(shù)據(jù) ****/ $shop_id = $this->_get('shop_id','intval'); $wxShare['title'] = $goodsData['name']; $wxShare['desc'] = $store['name']; $wxShare['imgUrl']= $this->siteUrl.$goodsData['logoimg']; $wxShare['link'] = $this->siteUrl.U('Goods/info',array('id'=>$goodsData['id'],'shop_id'=>$shop_id)); $this->assign('wxShare',$wxShare);
這里的地址,必須為絕對(duì)地址。否則相對(duì)地址,微信無法識(shí)別。
如果不設(shè)置,就會(huì)是默認(rèn)的標(biāo)題,默認(rèn)的logo,默認(rèn)的詳情。
設(shè)置了事件,就會(huì)按照自己想要的內(nèi)容分享出去。
4.我要分銷頁面,源碼
<!DOCTYPE html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <meta charset="utf-8" /> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no" name="viewport" /> <meta content="yes" name="apple-mobile-web-app-capable" /> <meta content="black" name="apple-mobile-web-app-status-bar-style" /> <meta name="format-detection" content="telephone=no" /> <title>【{sh:$store.name}】{sh:$goodsData.name}</title> <link type="text/css" rel="stylesheet" href="{sh::PUB}css/bootstrap.min.css"> <link type="text/css" rel="stylesheet" href="{sh::PUB}css/font-awesome.min.css"> <script src="{sh::PUB}js/jquery-1.10.2.min.js" type="text/javascript"></script> <style> body { background-color: #EFEFEF; min-width: 320px; max-width: 640px; margin: 0 auto; } .item-bottom { position: absolute; left: 0px; bottom: 0px; background: rgba(0, 0, 0, 0.4) none repeat scroll !important; width: 100%; color: #fff; line-height: 25px; padding-right: 5px; text-align: left; font-size: 13px; padding-left: 10px; } .qrcode img { width: 95%; } .qrcode strong { color: #cc0033; text-align: center; padding: 20px; display: block } .tip .title { height: 30px; margin: 10px; vertical-align: middle; line-height: 30px; } .tip .title img { padding: 5px; float: left; } .tip .title div { width: 100%; margin-left: 5px; height: 1px; background-color: #cc0033; } .tip .content { margin-left: 15px; margin-right: 15px; color: gray; } .tip .content strong { color: black; } .row_1 { width: 100%; display: -webkit-box; background-color: white; margin-bottom: 15px; } .row_2 { width: 100%; position: relative; background-color: white; } .row_2_1 { display: -webkit-box; margin-bottom: 10px; } .popover { display: inline; left: 80px; top: 10px; width: 70%; } .headimg { margin: 10px 10px; } .item-img { position: relative; } .price { color: #CC3300; font-size: 16px; } .money { display: inline-grid; font-size: 16px; padding: 10px 5px 5px 5px; } .sale { font-size: 14px; padding-left: 10px; color: gray; } .money_img { width: 70px; padding: 5px; } .popover-content { font-size: 14px; } </style> </head> <body> <div class="row_1"> <div class="left"><img class="money_img" src="{sh::RES}public/img/t2.png"></span> </div> <div class="right"> <div class="money">分銷傭金 <font color='#CC0000'>{sh:$commission}</font>元</div> <div class="sale">已銷售 <font color='#CC0000'> <php>echo ($goodsData['salecount'] + $goodsData['fakemembercount']);</php> </font>件</div> </div> </div> <div class="row_2"> <if condition="$wxuserData.nickname neq ''"> <div clas="row_2_1"> <div class="left"><img src="{sh:$wxuserData.headimgurl}" width="70px" class="headimg"></div> <div class="popover right"> <div class="arrow"></div> <div class="popover-content"> <p>我是 <font color='#FF9900'>{sh:$wxuserData.nickname}</font>, <br/><span>我為<font color='#FF9900'>{sh:$store.name}</font>代言。</span></p> </div> </div> </div> </if> <div class="row_2_2"> <div class="item-img"> <img class="item-img-logo" src="{sh:$goodsData.logoimg}" width="100%"> <div class="item-bottom"> <span>{sh:$goodsData.name}</span> <div> <span class="price">¥<strong>{sh:$goodsData.price}</strong></span> <small><s>¥{sh:$goodsData.oprice}</s></small> </div> </div> </div> </div> <div class="row_2_3 qrcode text-center"> <img src="{sh:$goodsData.qrcode}" width="100%"> <strong>長按二維碼 識(shí)別圖中二維碼</strong> </div> </div> <div class="row_3 tip"> <div class="title"> <i class="fa fa-sitemap"></i><span> 分銷如何賺錢</span> </div> <div class="content"> <div> <strong>第一步:</strong>轉(zhuǎn)發(fā)商品鏈接或商品二維碼圖片給微信好友; <br/> <br/> <strong>第二步:</strong>從您轉(zhuǎn)發(fā)的鏈接或圖片進(jìn)入商城的好友,系統(tǒng)將自動(dòng)鎖定成為您的客戶,他們?cè)谖⑿派坛侵匈徺I任何商品,您都可以獲得分銷傭金; <br/> <br/> <strong>第三步:</strong>您可以在分銷中查看【我的團(tuán)隊(duì)】和【分銷傭金】。好友確認(rèn)收貨后,傭金可提現(xiàn)。 <br/> <br/> </div> </div> </div> <include file="./Tpl/Store/Public/Public_foot.html" /> </body> <include file="./Tpl/Store/Wx_config.html"/> <script> // 微信JSSDK開發(fā) wx.ready(function () { // 分享給朋友 wx.onMenuShareAppMessage({ title: '{sh:$wxShare.title}', // 商品名 desc: '{sh:$wxShare.desc}', // 店鋪名 link: '{sh:$wxShare.link}', // 商品購買地址 imgUrl: '{sh:$wxShare.imgUrl}', // 分享的圖標(biāo) fail: function (res) { alert(JSON.stringify(res)); } }); // 分享到朋友圈 wx.onMenuShareTimeline({ title: '{sh:$wxShare.title}', // 商品名 link: '{sh:$wxShare.link}', // 商品購買地址 imgUrl: '{sh:$wxShare.imgUrl}', // 分享的圖標(biāo) fail: function (res) { alert(JSON.stringify(res)); } }); }); </script> </html>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript中json操作技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
JS中type="button"和type="submit"的區(qū)別
Submit是專門用于提交表單的Button,與Button的區(qū)別主要有兩點(diǎn):type=button 就單純是按鈕功能,type=submit 是發(fā)送表單 。下面通過本文給大家分享JS中type="button"和type="submit"的區(qū)別,感興趣的的朋友一起看看吧2017-07-07使用腳本控制網(wǎng)頁Table的顯示隱藏(全代碼)_AX
使用腳本控制網(wǎng)頁Table的顯示隱藏(全代碼)_AX...2006-12-12微信小程序?qū)崿F(xiàn)多選框功能的實(shí)例代碼
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)多選框功能及效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06js實(shí)現(xiàn)一款簡單踩白塊小游戲(曾經(jīng)很火)
本文給大家分享原生js實(shí)現(xiàn)曾經(jīng)很火的一款小游戲—?jiǎng)e踩白塊,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-12-12同步異步動(dòng)態(tài)引入js文件的幾種方法總結(jié)
下面小編就為大家?guī)硪黄疆惒絼?dòng)態(tài)引入js文件的幾種方法總結(jié)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09js實(shí)現(xiàn)模擬計(jì)算器退格鍵刪除文字效果的方法
這篇文章主要介紹了js實(shí)現(xiàn)模擬計(jì)算器退格鍵刪除文字效果的方法,涉及javascript字符串截取操作的相關(guān)技巧,需要的朋友可以參考下2015-05-05JavaScript兩種計(jì)時(shí)器的實(shí)例講解
今天小編就為大家分享一篇關(guān)于JavaScript兩種計(jì)時(shí)器的實(shí)例講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-01-01