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

摘要:
共享内容可以通过jssdk.˃'修改,jsApiList:['nMenuShareTimeline','nMenuSharedAppMessage','hooseImage','ploadImage']});2.加入并分享给好友,并分享给朋友圈事件//WeChat JSSDK开发wx.ready3。在后台获取wxShare数据/***获取微信共享数据***/$shop_id=$this-˃_Get;$wxShare['title']=$goodsData['name'];$wxShare['desc']=$store['name'];$wxShare['imgUrl']=$this-˃siteUrl.$货物数据['logimg'];$wxShare['link']=$this-˃siteUrl.U;$此-˃分配;这里的地址必须是绝对的。否则,微信无法识别相对地址。如果未设置,它将是默认标题、默认徽标和默认详细信息。

分享出去的内容,可以通过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);

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

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

如果不设置,就会是默认的标题,默认的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="http://t.zoukankan.com/{sh::PUB}css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="http://t.zoukankan.com/{sh::PUB}css/font-awesome.min.css">
    <script src="http://t.zoukankan.com/{sh::PUB}js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <style>
    body {
        background-color: #EFEFEF;
        min- 320px;
        max- 640px;
        margin: 0 auto;
    }
    
    .item-bottom {
        position: absolute;
        left: 0px;
        bottom: 0px;
        background: rgba(0, 0, 0, 0.4) none repeat scroll !important;
         100%;
        color: #fff;
        line-height: 25px;
        padding-right: 5px;
        text-align: left;
        font-size: 13px;
        padding-left: 10px;
    }
    
    .qrcode img {
         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 {
         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 {
         100%;
        display: -webkit-box;
        background-color: white;
        margin-bottom: 15px;
    }
    
    .row_2 {
         100%;
        position: relative;
        background-color: white;
    }
    
    .row_2_1 {
        display: -webkit-box;
        margin-bottom: 10px;
    }
    
    .popover {
        display: inline;
        left: 80px;
        top: 10px;
         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 {
         70px;
        padding: 5px;
    }
    
    .popover-content {
        font-size: 14px;
    }
    </style>
</head>

<body>
    <div class="row_1">
        <div class="left"><img   src="http://t.zoukankan.com/{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="http://t.zoukankan.com/{sh:$wxuserData.headimgurl}"   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   src="http://t.zoukankan.com/{sh:$goodsData.logoimg}" width="100%">
                <div class="item-bottom">
                    <span>{sh:$goodsData.name}</span>
                    <div>
                        <span class="price">&yen;<strong>{sh:$goodsData.price}</strong></span>
                        <small><s>&yen;{sh:$goodsData.oprice}</s></small>
                    </div>
                </div>
            </div>
        </div>
        <div class="row_2_3 qrcode text-center">
            <img src="http://t.zoukankan.com/{sh:$goodsData.qrcode}" width="100%">
            <strong>长按二维码&nbsp;识别图中二维码</strong>
        </div>
    </div>
    <div class="row_3 tip">
        <div class="title">
            <i class="fa fa-sitemap"></i><span>&nbsp;分销如何赚钱</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>

免责声明:文章转载自《微信JS-SDK实现自定义分享功能,分享给朋友,分享到朋友圈》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇snmp配置如何在Ubuntu 20.04 LTS上安装Redmine下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

【腾讯Bugly干货分享】打造“微信小程序”组件化开发框架

本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/2nQzsuqq7Avgs8wsRizUhw 作者:Gcaufy 导语 Bugly 之前发了一篇关于微信小程序的开发经验分享(点击阅读),小伙伴们在公众账号后台问了很多关于小程序开发方面的问题,精神哥在查阅相关内容...

记录uniapp的APP端分享到微信好友,链接为小程序页面,分享失败的BUG

记录uni-app的APP端分享到微信好友,链接为小程序页面,分享失败的BUG 分享到微信好友,链接为小程序端报错 16:59:19.617 fail:{"errMsg":"share:fail [Share微信分享:-6]send, http://ask.dcloud.net.cn/article/287","errCode":-100,"code":-...

微信分享之分享图片/分享图标不能显示

微信分享之分享图标/分享图片不能显示 主要是几个问题: 1、保证分享接口调用成功和分享路径的正确 2、保证分享图片的路径不要还用中文或全角字符 3、保证文案中不要含有红包、领取等敏感字符。 分享接口在未加载成功的时候,会出现错误。 做二种处理: 1、等页面加载完毕才调用分享接口,缺点,页面打开比较慢,用户体验不好 2、分析微信分享的实质,分享表示是页面的t...

微信内 H5 页面自定义分享

起源: 最近公司在做一个活动的h5页面,在微信内打开时需要进行微信授权,然后后端会重定向到这个页面并且携带了一些参数(openid等)。问题是点击微信的原生分享时,会把携带的这些参数一起分享出去,等于把用户信息泄露了。所以为了解决这个问题,只能实现自定义微信分享的功能,可以自定义分享的地址、标题、图标还有简介。 事先需要做的: 1.微信公众号:必须是经过...

前端实现禁用微信的分享菜单和启用菜单

一、页面加载禁用用户的分享菜单 function onBridgeReady() { WeixinJSBridge.call('hideOptionMenu'); } if (typeof WeixinJSBridge == "undefined") { if (document.addEventListe...

如何在不接入微信API的情况下自定义分享内容(图片、链接、标题)

方法如下: 1.设置分享title:动态改变document.title值即可: document.title = 'test'    2.设置分享图片:在页面隐藏一张尺寸大于290*290的图(图片需要容器包裹,设置容器css属性display:none即可): <div style="display:none"><img sr...