Call the jssdk instance and call the jssdk instance through WeChat sharing.

Source: Internet
Author: User

Share call jssdk instance, call jssdk instance

The web page is opened in, shared, detailed process

1. Problem Description

After half a day, we finally got it done. Let's talk about the basic requirements. It's very simple. The webpage is open and shared.
The webpage is in html format. The link is always displayed during sharing. After reading the code, jssdk is not called and a third-party platform sharing interface is called.

2. Problem Analysis

According to the official demo, we can see that the core is to get four parameters and configure wx. config.
The four parameters are appId, timestamp, nonceStr, and signature.
Not to mention appId, the last three are obtained based on the interface. If you are interested, you can refer to the official website, but you can leave it alone.

3. parsing ideas

Next, let's talk about my ideas. In js, call the interface deployed in jssdk through ajax and return the above parameters.
I tested PHP and wrote a myapi. php interface, which is very simple:

<? Phprequire_once "jssdk. php "; $ jssdk = new JSSDK (" Your appId "," Your appSecret "); $ signPackage = $ jssdk-> GetSignPackage (); $ data = array ('appid '=> $ signPackage ["appId"], 'timestamp' => $ signPackage ["timestamp"], 'noncestr' => $ signPackage ["nonceStr"], 'signature' => $ signPackage ["signature"]); echo json_encode ($ data );

Front-end page

<Script src = "http://res.wx.qq.com/open/js/jweixin-1.0.0.js"> </script> <script> $ (function () {$. ajax ({type: "GET", url :". /myapi. php ", data:" ", success: function (data) {var result = JSON. parse (data); if (result! = Null) {wx. config ({debug: false, appId: result. appId, timestamp: result. timestamp, nonceStr: result. nonceStr, signature: result. signature, jsApiList: ['onmenusharetimeline', 'onmenushareappmessage']}) ;}, error: function () {}}); window. required data = {title: 'title', desc: 'description', link: window. location. href, imgUrl: 'https: // gqrcode.alicdn.com/img? Type = cs & shop_id = 295323332 & seller_id = 1094878600 & w = 140 & h = 140 & el = q & v = 1 ', success: function () {alert ('success') ;}, cancel: function () {alert ('cancel') ;}}; wx. ready (function () {wx. onMenuShareAppMessage (response data); wx. onMenuShareTimeline (structured data) ;}); </script>

4. knowledge points

1. Share the use of jssdk
2. html calls ajax
3. Solve the connection issue during sharing.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

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.