Micro-letter Js-sdk custom sharing function Examples "share to friends/share to friends" _javascript tips

Source: Internet
Author: User
Tags function examples

The example of this article describes the micro-JS-SDK custom sharing function. Share to everyone for your reference, specific as follows:

Share out the content, can be modified by JSSDK.

1. Configure 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. Join share to friends, share to friends circle events

<script>//
micro-letter Jssdk Development
Wx.ready (function () {
  //share to friend
  Wx.onmenushareappmessage ({
   title: ' { SH: $wxShare. Title} ',//Product name
   desc: ' {sh: $wxShare. desc} ',//Shop name
   Link: ' {sh: $wxShare. Link} ',//product purchase address
   Imgurl: ' {sh: $wxShare. Imgurl} ',//Shared icon
   fail:function (res) {
    alert (json.stringify (res));
   }
  );
  //share to the circle
  of Friends Wx.onmenusharetimeline ({
   title: ' {sh: $wxShare. Title} ',//Product name
   Link: ' {sh:$ Wxshare.link} ',//product purchase address
   Imgurl: ' {sh: $wxShare. Imgurl} ',//share icon
   fail:function (res) {
    alert ( Json.stringify (res))
;}}; </script>

3. Background access to Wxshare data

/**** access to micro-credit sharing data ****/
$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);

The address here must be an absolute address. Otherwise, the relative address, the micro-letter is not recognized.

If not set, it will be the default title, the default logo, the default details.
When you set up an event, you share it with what you want.

4. I want to distribute the page, the source code

<! DOCTYPE html>  

More readers interested in JavaScript-related content can view this site: "JavaScript in the JSON Operation tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.