微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈

分享出去的内容,可以通过jssdk进行修改。

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开发
wx.ready(function () {
    // 分享给朋友
    wx.onMenuShareAppMessage({
      title: '{sh:$wxShare.title}', // 商品名
      desc: '{sh:$wxShare.desc}', // 店铺名
      link: '{sh:$wxShare.link}', // 商品购买地址
      imgUrl: '{sh:$wxShare.imgUrl}', // 分享的图标
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });

    // 分享到朋友圈
    wx.onMenuShareTimeline({
      title: '{sh:$wxShare.title}', // 商品名
      link: '{sh:$wxShare.link}', // 商品购买地址
      imgUrl: '{sh:$wxShare.imgUrl}', // 分享的图标
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
});
</script>

3.后台获取wxShare数据

/**** 获取微信分享数据 ****/
$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);

这里的地址,必须为绝对地址。否则相对地址,微信无法识别。

如果不设置,就会是默认的标题,默认的logo,默认的详情。
设置了事件,就会按照自己想要的内容分享出去。

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">[站外图片上传中……(2)]</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">[站外图片上传中……(3)]</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">
                [站外图片上传中……(4)]
                <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">
            [站外图片上传中……(5)]
            <strong>长按二维码 识别图中二维码</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>转发商品链接或商品二维码图片给微信好友;
                <br/>
                <br/>
                <strong>第二步:</strong>从您转发的链接或图片进入商城的好友,系统将自动锁定成为您的客户,他们在微信商城中购买任何商品,您都可以获得分销佣金;
                <br/>
                <br/>
                <strong>第三步:</strong>您可以在分销中查看【我的团队】和【分销佣金】。好友确认收货后,佣金可提现。
                <br/>
                <br/>
            </div>
        </div>
    </div>
    <include file="./Tpl/Store/Public/Public_foot.html" />
</body>
<include file="./Tpl/Store/Wx_config.html"/>
<script>
// 微信JSSDK开发
wx.ready(function () {
    // 分享给朋友
    wx.onMenuShareAppMessage({
      title: '{sh:$wxShare.title}', // 商品名
      desc: '{sh:$wxShare.desc}', // 店铺名
      link: '{sh:$wxShare.link}', // 商品购买地址
      imgUrl: '{sh:$wxShare.imgUrl}', // 分享的图标
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });

    // 分享到朋友圈
    wx.onMenuShareTimeline({
      title: '{sh:$wxShare.title}', // 商品名
      link: '{sh:$wxShare.link}', // 商品购买地址
      imgUrl: '{sh:$wxShare.imgUrl}', // 分享的图标
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
});
</script>
</html>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,100评论 18 139
  • 先来看看微信分享效果: 在没有集成微信分享js-sdk前是这样的:没有摘要,缩略图任意抓取正文图片 在集成微信分享...
    思梦PHP阅读 7,353评论 6 4
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 170,569评论 25 707
  • 园林131 蔡欣洁 01 1.辰山植物园植物景观丰富,请例举十张植物景观照片,结合形式美法则,分析该处植物景观...
    鸡蛋花旁的一棵菜阅读 1,051评论 0 0
  • 亲子日记第六天,今天的事说起来比较多。因为明天要考试了所以今天去阳光大道练考场,去了以后教练说要在那练一天,因...
    AA稳稳阅读 223评论 0 1