• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    Objective-C
  • Created almost 10 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cordova 微信分享插件

Cordova/PhoneGap 微信分享插件

此插件暂停维护, 如果不需要 WP 平台支持, 请使用 https://github.com/xu-li/cordova-plugin-wechat.

Inspired by https://github.com/xu-li/cordova-plugin-wechat

支持 iOS, WP, Android, 都有回调. 分享内容只支持文本, 图片, 和链接.

另外需要注意的是 Android 不仅需要审核通过, 还需要那什么签名吻合, 所以得要 release 的 keystore 来签名. 关于这个问题写了个指南, 如果 Android 搞不定的可以看看 Android 微信 SDK 签名问题.

安装

一定不要忘记加上后面的 --variable APP_ID=********.

cordova plugin add cordova-plugin-tx-wechat --variable APP_ID=[你的APPID]

另外貌似 Cordova 的变量信息是按平台保存的, 如果安装插件时尚未添加某个平台, 即便之前加上了变量, 之后添加平台时依旧会报错. 此时可以先卸载插件, 添加平台后带上变量重新安装.

如果是 Visual Studio Tools for Apache Cordova, 可以这样配置 App ID:

<vs:plugin name="cordova-plugin-tx-wechat" version="0.3.1">
    <param name="APP_ID" value="[你的APPID]" />
</vs:plugin>

配置

其实安装后就可以用了! 零配置哟哈哈哈! 下面列一些注意事项.

config.xml

可能需要添加一些权限, 比如安卓貌似是要添加这些:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

反正我没添加, debug/release 都没问题, 不知道提交商店会不会有情况.

iOS 相关: libWeChatSDK.a

src/ios/libWeChatSDK.a 这个文件有两个版本, 一个是 iPhone Only 的, 要小一些, 应该是最后生产环境用的. 我放进去的是完整版本, 要大一倍 (应该是包含了 x86 架构方便模拟器 debug), 可以自己去下载 官方 SDK 然后替换掉 platforms/ios/应用名称/Plugins 目录下的 libWeChatSDK.a.

使用

// 在 device ready 后.

// 分享 API
WeChat
    .share('文本', WeChat.Scene.session, function () {
        console.log('分享成功~');
    }, function (reason) {
        console.log(reason);
    });

// 或者 (更多选项见后).
WeChat
    .share({
        type: WeChat.ShareType.webpage,
        title: '链接',
        description: '链接描述',
        url: 'https://wordsbaking.com/'
    }, WeChat.Scene.timeline, function () {
        console.log('分享成功~');
    }, function (reason) {
        // 分享失败
        console.log(reason);
    });

// 检查微信安装情况
// WP 始终返回 true
WeChat
    .isInstalled(function(installed) {
        console.log('WeChat installed='+installed);
    }, function(reason) {
        console.log(reason);
    });

API 定义

declare module WeChat {
    /** 分享场景 */
    enum Scene {
        /** 用户自选, 安卓不支持 */
        chosenByUser,
        /** 聊天 */
        session,
        /** 朋友圈 */
        timeline
    }

    /** 多媒体分享类型, 目前只支持 image, webpage */
    enum ShareType {
        app = 1,
        emotion,
        file,
        image,
        music,
        video,
        webpage
    }
    
    /** 分享选项 */
    interface IMessageOptions {
        /** 多媒体类型, 默认为 webpage */
        type: ShareType;
        /** 标题 */
        title?: string;
        /** 描述 */
        description?: string;
        /** 缩略图的 base 64 字符串 */
        thumbData?: string;
        /** 分享内容的 url, type 为 image 是就是图片的 url, 为 webpage 时就是链接的 url */
        url?: string;
        /** 分享内容的 base 64 字符串, 与 url 二选一 */
        data?: string;
    }

    // 分享.
    function share(text: string, scene: Scene, onfulfilled: () => void, onrejected: (reason) => void): void;
    function share(options: IMessageOptions, scene: Scene, onfulfilled: () => void, onrejected: (reason) => void): void;
}

More Repositories

1

typescript-guide

TypeScript 中文指南
278
star
2

clime

⌨ The command-line interface framework for TypeScript.
TypeScript
252
star
3

cordova-plugin-tts

Cordova Text-to-Speech Plugin (Maintainer WANTED!)
Java
177
star
4

wordsbaking-plus-chrome

词焙+ (WordsBaking+) 是词焙的重要组件, 方便用户把平时浏览网页时遇到的生词收集起来放进词焙生词本. 同时也是一个好用的划词翻译插件. http://wordsbaking.com
JavaScript
71
star
5

a-plus-dictionary

A Chrome extension based on Google Dictionary, provides better UI and shows the meanings in both your language and English.
JavaScript
61
star
6

thenfail

🏳 Just another Promises/A+ implementation written in TypeScript.
TypeScript
49
star
7

vs-force-utf8

Force UTF8 Extension for Visual Studio
C#
43
star
8

drop

Just another MV* framework
TypeScript
35
star
9

deprecated-decorator

A simple decorator for deprecated methods and properties.
TypeScript
32
star
10

magicspace

Toolkit for living boilerplate.
TypeScript
32
star
11

vio

📨 An express "endware" that takes your feelings into consideration.
TypeScript
29
star
12

ruff-home

Home (Web Framework) for Ruff.
TypeScript
28
star
13

vscode-es-quotes

ES Quotes Extension for Visual Studio Code.
TypeScript
26
star
14

entrance-decorator

A minimal solution of dependency injection for projects that scale.
TypeScript
25
star
15

plug2proxy

Transparent Proxy over HTTP2 or QUIC.
Rust
21
star
16

nodemand

Restart Node.js process on required modules change.
JavaScript
20
star
17

villa

🏡 Villa is a set of promise utilities for async-await-ready environment.
TypeScript
19
star
18

memorize-decorator

TypeScript
18
star
19

regex-tools

A simple tool for managing long regular expressions.
TypeScript
17
star
20

promise-pool

A task pool based on Promise (Q).
TypeScript
12
star
21

turning

Automated state transition testing.
TypeScript
10
star
22

vscode-console

Visual Studio Code Extension: Open Console in User-defined Console.
TypeScript
8
star
23

ruff-menu

Awesome Menu for Ruff LCD (lcd1602).
TypeScript
8
star
24

extendable-error

A simple extendable error class that extends Error.
TypeScript
8
star
25

vejis

A "grammer level" framework for JavaScript
JavaScript
8
star
26

x-value

A medium-neutral runtime type validation library.
TypeScript
8
star
27

touch-delegate

A gesture library based on extendable identifiers.
JavaScript
7
star
28

rateman

Rateman is a redis-based rate limiter with multi-window support.
TypeScript
7
star
29

ruff-promise

ES6 Promise for Ruff (https://ruff.io) based on ThenFail v0.4 (https://github.com/vilic/thenfail).
TypeScript
7
star
30

vscode-sensitive-replace

Replace selections while preserving cases.
TypeScript
6
star
31

henge

🗃 Henge generates artifacts for upstream projects and makes them configurable dependencies for downstream projects.
TypeScript
5
star
32

auto-loopback-exempt

Automatically exempt loopback for all and newly added applications.
JavaScript
5
star
33

prever-start

JavaScript
5
star
34

inplate

A command-line tool processing files with in-place template.
JavaScript
5
star
35

vlight

A lightweight syntax highlighter for JavaScript/HTML/CSS
JavaScript
5
star
36

backpage

Naive static HTML streaming based on React for Node.js CLI applications.
TypeScript
5
star
37

vio-demos

Demos for VIO
TypeScript
5
star
38

ruff-fetch

A simplified version of `window.fetch` written for Ruff.
TypeScript
4
star
39

biu-link

A simple URL shorter.
HTML
4
star
40

baseman

Integration test framework for Node.js
TypeScript
4
star
41

unmount-animation-clone

A simple utility component that clones the DOM element for animation before it unmounts.
TypeScript
4
star
42

npm-fork

Publish forks of npm packages with ease.
TypeScript
4
star
43

clime-slack

Shim and utilities for Slack slash commands building upon Clime.
TypeScript
3
star
44

js-operator-overloading

Overload operators in JavaScript (for fun).
JavaScript
3
star
45

gcvs

Git-CVS Workflow Utilities.
Shell
3
star
46

ClassScheduleProxy

C#
3
star
47

typescript-techniques

Hopefully useful techniques for TypeScript in practice.
3
star
48

docheat

A "cheating" tool that generates brief API references for TypeScript libraries with links to source code.
TypeScript
3
star
49

black-object

Blackbox mock with predefined interaction scripts.
TypeScript
3
star
50

typesafe-mongo

TypeSafe utilities for official MongoDB Node.js driver
TypeScript
3
star
51

multikey-map

TypeScript
2
star
52

vts

V-branded TypeScript coding standard
JavaScript
2
star
53

is-typeof-property

Simple utilities for tuple type narrowing...
TypeScript
2
star
54

tag-contacts

Just another simple UI widget for entering emails as contacts (2013).
JavaScript
2
star
55

main-function

A simple wrapper that handles error and return code.
TypeScript
2
star
56

lucky-dns

Lucky DNS, heavily inspired by SinoDNS and ChinaDNS.
TypeScript
1
star
57

hola-code

VS Code utilities for workflow at Hola.
TypeScript
1
star
58

q-retry

A shell for Q to enable retries.
JavaScript
1
star
59

lucky-vpn

Windows-friendly utilities that generate automation scripts for VPN connection.
TypeScript
1
star
60

v-query

A simple selector.
JavaScript
1
star
61

thenfail-core

Core of ThenFail (https://github.com/vilic/thenfail).
TypeScript
1
star
62

ViT

A mobile twitter client
1
star
63

cross-pm

Spawn npm/yarn/pnpm accordingly based on different lock files found in the context.
JavaScript
1
star
64

vilic.github.io

Project index of mine
HTML
1
star
65

ruff-t

T (Testing Framework) for Ruff.
TypeScript
1
star
66

qform

一段黑历史
JavaScript
1
star
67

semver-match

A simple function that conforms npm package version matching behavior.
TypeScript
1
star
68

ClassSchedule

Class Schedule for CQU
C#
1
star
69

Analyzer

AIESEC Form Analyzer
JavaScript
1
star
70

socket-jet

Minimalist package for data packets over socket connections.
TypeScript
1
star
71

get-or-create

A simple utility to get or create nested property and element in place.
TypeScript
1
star
72

boring-cache

TypeScript
1
star
73

air-proxy-enabled-http-request-for-js

A HTTP request implementation based on air.Socket, support HTTP only.
JavaScript
1
star
74

tracked-history

It tracks browser history so that we can restore history stack with snapshots.
TypeScript
1
star
75

super-heavy-launching

Super Heavy Launching Animation
HTML
1
star
76

cordova-plugin-fix-wp-bouncing

An acceptable solution for Windows Phone bouncing issue
C#
1
star
77

vilic

1
star
78

desktop-matters

Add your desktop computer as Matter devices.
TypeScript
1
star