# cdv-plugn-wechat **Repository Path**: zhpcode/cdv-plugn-wechat ## Basic Information - **Project Name**: cdv-plugn-wechat - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-12-25 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # cordova plugin for wechat 微信插件 >## DESC cordova集成微信SDK插件,实现三方移动应用调用微信相关功能 >## Version 日期 | 版本 | 作者 ------------ | -------- | ----- 2018.12.5 | v1.0.0 | zhuhaipeng | | >## Function list 功能列表 - 检查微信是否安装 - 三方应用分享文本到微信 - 三方应用分享图片或media到微信 - 三方应用请求微信授权 >## Install 1. `cordova plugin add --variable WECHATAPPID=` 参数 | 描述 ----------- | ------------ | | 插件所在本地目录(或git地址) | 微信AppID(需申请) 2. `cordova build android ` OR `cordova build ios` 3. if remove plugin : `cordova plugin rm cordova-plugin-wechat` >## Usage ##### 1. 检验微信是否安装 Check if wechat app is installed --- ```javascript Wechat.isInstalled(function (installed) { console.log('wxshare ==' + installed) alert("Wechat installed: " + (installed ? "Yes" : "No")); }, function (reason) { alert("Failed: " + reason); }); ``` ##### 2. 分享文本到微信朋友圈或好友 Share text --- ```javascript Wechat.share({ text: "wechat share text demo..", scene: Wechat.Scene.TIMELINE }, function () { console.log('wxshare success return..') alert("Success") }, function (reason) { console.log('wxshare failed return..') alert("Failed: " + reason) }); ``` ##### 3. 分享图片到微信 Share media(e.g. link, photo, music, video etc) --- ```javascript Wechat.share( { message: { title: "Hi, there", description: "This is description.", thumb: "www/img/logo.png", mediaTagName: "test tag name", messageExt: "测试字段", messageAction: "test...", media: { type: Wechat.Type.IMAGE, // 图片类型 image: "" } }, scene: Wechat.Scene.SESSION }, function () { console.log('wxshare success return..'); alert("Success") // TODO: }, function (reason) { console.log('wxshare failed return..' + reason); alert("Failed: " + reason) // TODO: } ); ``` ##### 4. 三方应用调用微信授权 wechat OAuth --- ```javascript // 授权域 let scope = Wechat.Auth.SCOPE; // 请求及回调状态 let state = "_" + (+new Date()); Wechat.auth(scope, state, function (response) { // 返回code,可用于获取access_token 去做自己的处理 alert(response.code) // 打印返回所有内容 console.log(JSON.stringify(response)); // TODO: return ; }, function (reason) { // 弹出失败的原因 alert("Failed: " + reason); // TODO: return; }); ``` >## Log 更新日志 日期 | 版本 | 备注 | 作者 ----------- | ------ | -------- | ----- 2018.12.5 | v1.0.0 | 集成微信sdk | zhuhaipeng