# cordova-plugin-amos-wechat

> A cordova plugin, a JS version of Wechat SDK

Latest version **0.0.12** (published 2020-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install cordova-plugin-amos-wechat
pnpm add cordova-plugin-amos-wechat
yarn add cordova-plugin-amos-wechat
bun add cordova-plugin-amos-wechat
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2020-03-18 |
| First published | 2019-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.1 MB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | xu.li |
| Maintainers | amoslee |
| Keywords | cordova, wechat, weixin, share, ecosystem:cordova, cordova-ios, cordova-android |

## Links

- npm: https://www.npmjs.com/package/cordova-plugin-amos-wechat
- Repository: https://github.com/xu-li/cordova-plugin-amos-wechat
- Homepage: https://github.com/xu-li/cordova-plugin-amos-wechat#readme
- Issues: https://github.com/xu-li/cordova-plugin-amos-wechat/issues
- npm.io page: https://npm.io/package/cordova-plugin-amos-wechat

## Dependencies (1)

- [shelljs](https://npm.io/package/shelljs.md) ^0.5.3

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.12 (latest) — 2020-03-18
- 0.0.11 — 2020-03-17
- 0.0.10 — 2020-03-16
- 0.0.8 — 2019-12-09
- 0.0.7 — 2019-11-30
- 0.0.6 — 2019-11-30
- 0.0.5 — 2019-11-30
- 0.0.4 — 2019-11-30
- 0.0.3 — 2019-11-30
- 0.0.2 — 2019-11-20
- 0.0.1 — 2019-11-19

## README

![Active](https://www.repostatus.org/badges/latest/active.svg)
![Downloads](https://img.shields.io/npm/dt/cordova-plugin-amos-wechat.svg)
![version](https://img.shields.io/npm/v/cordova-plugin-amos-wechat/latest.svg)

# cordova-plugin-amos-wechat

A cordova plugin, a JS version of Wechat SDK

# Feature

* check wechat client is installed;
* Share text, image, link,music,video,miniprogram to wechat timeline,session or favorite;
* open wechat auth;
* send wechat payment request;
* open wechat miniprogram;

# Documentation

[文档](https://jasonz1987.github.io/cordova-wechat-docs/) · [教程](https://www.jason-z.com/course/3) · [FAQ](https://jasonz1987.github.io/cordova-wechat-docs/docs/faq) · [DEMO](https://jasonz1987.github.io/cordova-wechat-docs/docs/demo)

# Install

```shell
cordova plugin add cordova-plugin-amos-wechat --variable wechatappid=YOUR_WECHAT_APPID
```

```shell
cordova build ios
cordova build android
```

# Usage 

## Check if wechat is installed

```Javascript
Wechat.isInstalled(function (installed) {
    alert("Wechat installed: " + (installed ? "Yes" : "No"));
}, function (reason) {
    alert("Failed: " + reason);
});
```

## Authenticate using Wechat
```Javascript
var scope = "snsapi_userinfo",
    state = "_" + (+new Date());
Wechat.auth(scope, state, function (response) {
    // you may use response.code to get the access token.
    alert(JSON.stringify(response));
}, function (reason) {
    alert("Failed: " + reason);
});
```

## Share text
```Javascript
Wechat.share({
    text: "This is just a plain string",
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
```

## Share media(e.g. link, photo, music, video etc)
```Javascript
Wechat.share({
    message: {
        title: "Hi, there",
        description: "This is description.",
        thumb: "www/img/thumbnail.png",
        mediaTagName: "TEST-TAG-001",
        messageExt: "这是第三方带的测试字段",
        messageAction: "<action>dotalist</action>",
        media: "YOUR_MEDIA_OBJECT_HERE"
    },
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
```

### Share link
```Javascript
Wechat.share({
    message: {
        ...
        media: {
            type: Wechat.Type.WEBPAGE,
            webpageUrl: "http://www.jason-z.com"
        }
    },
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
```

### Share mini program
```Javascript
Wechat.share({
    message: {
        ...
        media: {
            type: Wechat.Type.MINI,
            webpageUrl: "https://www.jason-z.com", // 兼容低版本的网页链接
            userName: "wxxxxxxxx", // 小程序原始id
            path: "user/info", // 小程序的页面路径
            hdImageData: "http://wwww.xxx.com/xx.jpg", // 程序新版本的预览图二进制数据 不超过128kb 支持 地址 base64 temp
            withShareTicket: true, // 是否使用带shareTicket的分享
            miniprogramType: Wechat.Mini.RELEASE 
        }
    },
    scene: Wechat.Scene.SESSION   // 小程序仅支持聊天界面
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
```

## Send payment request
```Javascript
// See https://github.com/xu-li/cordova-plugin-amos-wechat-example/blob/master/server/payment_demo.php for php demo
var params = {
    partnerid: '10000100', // merchant id
    prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
    noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
    timestamp: '1439531364', // timestamp
    sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
};

Wechat.sendPaymentRequest(params, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
```

## Choose invoices from card list
```Javascript
//offical doc https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1496561749_f7T6D
var params = {
    timeStamp: '1510198391', // timeStamp
    signType: 'SHA1', // sign type
    cardSign: 'dff450eeeed08120159d285e79737173aec3df94', // cardSign
    nonceStr: '5598190f-5fb3-4bff-8314-fd189ab4e4b8', // nonce
};

Wechat.chooseInvoiceFromWX(params,function(data){
    console.log(data);
},function(){
    alert('error');
})
```

## open wechat mini program 
```Javascript
//offical doc https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21526646437Y6nEC&token=&lang=zh_CN
var params = {
    userName: 'gh_d43f693ca31f', // userName
    path: 'pages/index/index?name1=key1&name2=key2', // open mini program page
    miniprogramType: Wechat.Mini.RELEASE // Developer version, trial version, and official version are available for selection
};

Wechat.openMiniProgram(params,function(data){
    console.log(data); // data:{extMsg:""}  extMsg: Corresponds to the app-parameter attribute in the Mini Program component <button open-type="launchApp">
},function(){
    alert('error');
})
```

more usage  please see [https://jasonz1987.github.io/cordova-wechat-docs/docs/usages](https://jasonz1987.github.io/cordova-wechat-docs/docs/usages)

# Join us

QQ群：190808518 
[![cordova-wechat官方交流群](https://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=8279476de172cacb72a51a5630744316c0069620ad8b33be3abee243af2cc001)

# Donate

we need your support to improve open source software ,if we induce your develop time ,welcome to donate us.

[![paypal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/jasonz1987/6.66)

![donate.png](donate.png)

# LICENSE

[MIT LICENSE](http://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/cordova-plugin-amos-wechat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
