Coder Social home page Coder Social logo

damien-ls / tiny-wechat-jssdk-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotgreg/tiny-wechat-jssdk-server

0.0 1.0 0.0 64 KB

A Tiny Wechat JSSDK API server + its frontend script for a lightning fast JSSDK integration, one microservice for all your H5s and websites

PHP 32.96% JavaScript 67.04%

tiny-wechat-jssdk-server's Introduction

Tiny Wechat JSSDK API server + its frontend script

Description

  • Simple API for wx JSSDK + its frontend js plugin for a lightning fast JSSDK functionnalities implementation

  • Designed to :

    • Be used as a tool for rapid prototyping on wechat JSSDK, small websites and H5 quick solution
    • Have no dependencies, no database connection (working using json to store ticket/token)
    • Be stupid simple to use, edit and upgrade, based on no framework, pure vanilla php and js
    • Be a standalone microservice api (ex https://api.wx.mycompany.cn) work with several APPIDs, use a unique api for all your H5 and websites
    • Be Frontend Framework-friendly (VueJS, React, Angular) as the Javascript wxSharing.js includes a watcher that will update the signature if a URI change is detected
    • Easen the task of JSSDK debugging, especially on workflows requiring compilation before reaching the server production (Webpack or MeteorJS), as the js script can be embedded as external js ressource from your app on https://api.wx.mycompany.cn/script/wxSharing.js, thus easily editable (same design than the https://www.google-analytics.com/analytics.js embed)

Why

  • Wechat JSSDK API implementation on websites and H5 is a pain, requiring backend, storage and frontend logic.
  • Debugging wechat JSSDK is even more a nightmare, as it usually requires you to debug your js code on the production server (as it only works on whitelisted domains). Adding it to some workflows where compiling is required before deployment (like Webpack or MeteorJS), the task could easily takes hours, thus editing the JS script on a third party server you have total control on it solves a lot of issues.
  • Using this system, you can setup once and for all your websites and H5 an API system, the only thing needed is adding the wxSharing.js on your pages.

Installation

Setup API Server

  1. Make sure to whitelist your server IP inside Wechat Official Account backend

  2. Edit your config by copying config.example.php to config.php

  3. Secure the keys folder that nobody outside your script can access it, it will contain the Tokens and Tickets

on Nginx you can use :
location /keys {
 deny all;
}

On your Application/Website

  1. Make sure to whitelist your Domain name as JSSDK Allowed URL inside Wechat Official Account backend

  2. Add <script src="https://api.wx.yourcompany.cn/script/wxSharing.js"></script> in your frontend app (on vueJS/React/Angular, simply include it inside your root index.html)

  3. Configure the object window.wxSharing in each of your page, working as well on Frontend frameworks using History.push (VueJS, Reach, Angular) as the script regularly checks the URL and call the API if any change

window.wxSharing = {
    debug: true,
    apiUrl: 'https://api.wx.yourcompany.cn',
    appid: 'wx56e08b08894f0d35',
    title: 'hello',
    desc: 'world',
    link: 'https://mywebsite.cn', 
    imgUrl: 'https://mywebsite.cn/static/img/wechat-sharing.png', // Absolute url only
    success: function // optional,
    cancel: function  // optional
  }

API Endpoints

  1. getsignature

    • Example: api/index.php?action=getsignature&appid=wx56e1111111111&appurl=https://mycompany.cn&signuri=/home.html
    • Description: Get the signature necessary to use JSSDK on a page, used internally by script/wxSharing.js
  2. clean

    • Example: api/index.php?action=clean&appid=wx56e1111111111&password=yourpasswordhere
    • Description: Clean the JS token and JS ticket for the selected APPID, that next time 'getsignature' is called, it refreshs it

tiny-wechat-jssdk-server's People

Contributors

dotgreg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.