Git Product home page Git Product logo

wechat.js's Introduction

wechat.js

微信打开 DEMO 地址:http://sofish.github.io/wechat.js,或者扫一扫下面的二维码进行分享:

sofish/wechat.js

下面是 API 详解,使用可参考上面 DEMO 的源代码。微信的 API 是有点恶心的,也不断在变,如果发现问题请给提 issue 或者 pull-request 吧。

1、使用指南

一、唯一接口:wechat,有「分享」+ 「操作」两种类型

// 分享
wechat('friend', data, callback);     // 朋友
wechat('timeline', data, callback);   // 朋友圈
wechat('weibo', data, callback);      // 微博

// 操作
wechat('hideToolbar', callback);      // 隐藏底部菜单
wechat('hideOptionMenu', callback);   // 隐藏右上角分享按钮

wechat('network', callback);          // 查看用户当前网络
// 1. wifi
// 2. edge 非 wifi,包含 3G/2G
// 3. fail 网络断开连接
// 4. wwan 2g/3g

二、data 「属性」支持函数

因为有些数据是需要拼接,或者在点击分享按钮的时候可能才存在的,但是又不想写很麻烦时机判断,这里 data 中支持传入函数,比如:

// 一般的数据
var data = {
  'app': 'APP ID',    // 选填,默认为空
  'img': '图片 URL',   // 选填,默认为空或者当前页面第一张图片
  'link': '链接',
  'desc': '描述',
  'title': '标题'
};

// 假设我们在一个单页应用,title 可能是 js 在数据载入后才有的,那么可以这样来:
var getTitile = function() {
  return document.title;
};

// 这个数据 ,最终 wechat.js 会自动转换
var data = {
  // 这里需要特别说明的是,建议不要用新浪微博的图片地址,要么你试试,哈哈
  'img': '图片 URL',
  
  'link': '链接',
  'desc': '描述',
  'title': getTitle()
};

三、回调

var callback = function() {
  // 返回的数据并不统一,接口已经尽量统一,我觉得微信公司现在缺 js 程序员
  // 也有一些是很恶心的
  console && console.log(argument);
};

wechat('timeline' data, callback);

2、授权

MIT License

wechat.js's People

Contributors

sofish avatar

Watchers

James Cloos avatar 子纲|Rahul 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.