Home Web Front-end JS Tutorial Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments]

Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments]

Dec 05, 2016 am 11:28 AM
WeChat

The example in this article describes the custom sharing function of WeChat JS-SDK. Share it with everyone for your reference, the details are as follows:

The shared content can be modified through jssdk.

1. Configure jssdk

Wx_config.html

<?php
import("@.ORG.jssdk");
$jssdk = new JSSDK(C(&#39;oauth_config.appid&#39;), C(&#39;oauth_config.appsecret&#39;));
$signPackage = $jssdk->GetSignPackage();
?>
Copy after login

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
  wx.config({
    debug: false,
    appId: &#39;<?php echo $signPackage["appId"];?>&#39;,
    timestamp: &#39;<?php echo $signPackage["timestamp"];?>&#39;,
    nonceStr: &#39;<?php echo $signPackage["nonceStr"];?>&#39;,
    signature: &#39;<?php echo $signPackage["signature"];?>&#39;,
    jsApiList: [
      &#39;onMenuShareTimeline&#39;,
      &#39;onMenuShareAppMessage&#39;,
      &#39;chooseImage&#39;,
      &#39;uploadImage&#39;
    ]
  });
</script>
Copy after login

2. Join share with friends, share to Moments event

<script>
// 微信JSSDK开发
wx.ready(function () {
  // 分享给朋友
  wx.onMenuShareAppMessage({
   title: &#39;{sh:$wxShare.title}&#39;, // 商品名
   desc: &#39;{sh:$wxShare.desc}&#39;, // 店铺名
   link: &#39;{sh:$wxShare.link}&#39;, // 商品购买地址
   imgUrl: &#39;{sh:$wxShare.imgUrl}&#39;, // 分享的图标
   fail: function (res) {
    alert(JSON.stringify(res));
   }
  });
  // 分享到朋友圈
  wx.onMenuShareTimeline({
   title: &#39;{sh:$wxShare.title}&#39;, // 商品名
   link: &#39;{sh:$wxShare.link}&#39;, // 商品购买地址
   imgUrl: &#39;{sh:$wxShare.imgUrl}&#39;, // 分享的图标
   fail: function (res) {
    alert(JSON.stringify(res));
   }
  });
});
</script>
Copy after login

3. Get wx in the background Share data

/**** 获取微信分享数据 ****/
$shop_id = $this->_get(&#39;shop_id&#39;,&#39;intval&#39;);
$wxShare[&#39;title&#39;] = $goodsData[&#39;name&#39;];
$wxShare[&#39;desc&#39;] = $store[&#39;name&#39;];
$wxShare[&#39;imgUrl&#39;]= $this->siteUrl.$goodsData[&#39;logoimg&#39;];
$wxShare[&#39;link&#39;] = $this->siteUrl.U(&#39;Goods/info&#39;,array(&#39;id&#39;=>$goodsData[&#39;id&#39;],&#39;shop_id&#39;=>$shop_id));
$this->assign(&#39;wxShare&#39;,$wxShare);
Copy after login

The address here must be an absolute address. Otherwise, WeChat cannot recognize the relative address.

Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments]

If not set, it will be the default title, default logo, and default details.
After setting the event, it will be shared according to the content you want.

4. I want distribution page, source code



  
  
  
  
  
  
  【{sh:$store.name}】{sh:$goodsData.name}
  
  
  
  


  
Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments]
分销佣金 {sh:$commission}
已销售 echo ($goodsData['salecount'] + $goodsData['fakemembercount']);
Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments]

我是 {sh:$wxuserData.nickname}
我为{sh:$store.name}代言。

{sh:$goodsData.name}
¥{sh:$goodsData.price} ¥{sh:$goodsData.oprice}
Detailed explanation of WeChat JS-SDK custom sharing function examples [Share to friends/Share to Moments] 长按二维码 识别图中二维码
分销如何赚钱
第一步:转发商品链接或商品二维码图片给微信好友;

第二步:从您转发的链接或图片进入商城的好友,系统将自动锁定成为您的客户,他们在微信商城中购买任何商品,您都可以获得分销佣金;

第三步:您可以在分销中查看【我的团队】和【分销佣金】。好友确认收货后,佣金可提现。

<script> // 微信JSSDK开发 wx.ready(function () { // 分享给朋友 wx.onMenuShareAppMessage({ title: &#39;{sh:$wxShare.title}&#39;, // 商品名 desc: &#39;{sh:$wxShare.desc}&#39;, // 店铺名 link: &#39;{sh:$wxShare.link}&#39;, // 商品购买地址 imgUrl: &#39;{sh:$wxShare.imgUrl}&#39;, // 分享的图标 fail: function (res) { alert(JSON.stringify(res)); } }); // 分享到朋友圈 wx.onMenuShareTimeline({ title: &#39;{sh:$wxShare.title}&#39;, // 商品名 link: &#39;{sh:$wxShare.link}&#39;, // 商品购买地址 imgUrl: &#39;{sh:$wxShare.imgUrl}&#39;, // 分享的图标 fail: function (res) { alert(JSON.stringify(res)); } }); }); </script>
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Can I see visitors in WeChat Moments? Can I see visitors in WeChat Moments? May 06, 2024 pm 01:30 PM

1. WeChat is a social platform that pays attention to privacy protection. Users cannot see who has visited their Moments or personal homepage. 2. This design is intended to protect user privacy and avoid potential harassment or snooping. 3. Users can only see the likes and comments records in their circle of friends, further ensuring the confidentiality of personal information.

There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions Sep 02, 2024 pm 10:45 PM

Thanks to netizens Qing Qiechensi, HH_KK, Satomi Ishihara and Wu Yanzu of South China for submitting clues! According to news on September 2, there are recent rumors that "iPhone 16 may not support WeChat." In response to this, a reporter from Shell Finance called Apple's official hotline. Apple's technical consultant in China responded that whether iOS systems or Apple devices can continue to use WeChat, and WeChat The issue of whether it can continue to be listed and downloaded on the Apple App Store requires communication and discussion between Apple and Tencent to determine the future situation. Software App Store and WeChat Problem Description Software App Store technical consultant pointed out that developers may need to pay fees to put software on the Apple Store. After reaching a certain number of downloads, Apple will need to pay corresponding fees for subsequent downloads. Apple is actively communicating with Tencent,

How to recover deleted chat history on WeChat How to recover deleted chat history on WeChat May 06, 2024 pm 01:29 PM

1. To recover deleted WeChat chat history, you need to use two mobile phones for data migration. 2. On the old phone, click [Me] → [Settings] → [Chat] → [Chat History Migration and Backup]. 3. Select [Migrate] and set the target device platform. After selecting the chat history to be restored, click [Start]. 4. Then log in to the same account on the new phone and scan the QR code on the old phone to start the migration. 5. After the migration is completed, the deleted chat history will be restored to the new phone.

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

DeepSeek: A powerful AI image generation tool! DeepSeek itself is not an image generation tool, but its powerful core technology provides underlying support for many AI painting tools. Want to know how to use DeepSeek to generate images indirectly? Please continue reading! Generate images with DeepSeek-based AI tools: The following steps will guide you to use these tools: Launch the AI ​​Painting Tool: Search and open a DeepSeek-based AI Painting Tool (for example, search "Simple AI"). Select the drawing mode: select "AI Drawing" or similar function, and select the image type according to your needs, such as "Anime Avatar", "Landscape"

How to set WeChat background image How to set WeChat background image Apr 26, 2024 am 11:01 AM

1. Open the WeChat app, click [Me] at the bottom of the interface, and select the [Settings] function. 2. Click [Chat], click [Chat Background] to enter the chat background setting interface. 3. Click [Select Background Image] or [Select from Album] or [Take a Photo]. 4. Select and click the picture you want to use, and then click [Use] in the upper right corner.

Is WeChat Lingqiantong safe? Is WeChat Lingqiantong safe? Apr 29, 2024 am 10:23 AM

1. WeChat Lingqiantong adopts a multi-layer security mechanism, including password protection, real-name authentication, mobile phone binding, etc., to ensure the security of user accounts. 2. WeChat Pay uses a variety of encryption methods, including SSL encrypted transmission, real-time monitoring, etc., to ensure transaction security. 3. WeChat Pay also cooperates with banks and financial institutions to implement risk control and prevention measures to monitor and handle abnormal transactions. 4. When using WeChat Lingqiantong, users should also strengthen the protection of personal accounts, set complex passwords, change passwords regularly, and not disclose personal information at will.

How to transfer WeChat chat history to another mobile phone How to transfer WeChat chat history to another mobile phone May 08, 2024 am 11:20 AM

1. On the old device, click "Me" → "Settings" → "Chat" → "Chat History Migration and Backup" → "Migrate". 2. Select the target platform device to be migrated, select the chat records to be migrated, and click "Start". 3. Log in with the same WeChat account on the new device and scan the QR code to start chat record migration.

How to recover chat history after deleting friends on WeChat How to recover chat history after deleting friends on WeChat Apr 29, 2024 am 11:01 AM

1. Open the WeChat app, click [Address Book] at the bottom of the interface, and click [New Friend]. 2. Enter the friend’s WeChat ID or nickname in the search box at the top of the page. 3. If the other party has not deleted the user, the user can find the friend in the search results. 4. Click on the friend to enter the chat window with him or her, and you can view the previous chat history.

See all articles