Weixin  
微信插件
Adding the Plugin to your project



1.add weixin.js to your www folder and include it to your html file below cordova.js

  1. <script type="text/javascript" charset="utf-8" src="cordova.js">
  2. <script type="text/javascript" charset="utf-8" src="weixin.js">

复制代码

2.Add WeChatSDK & SinaWeixinPlugin src files to your project.

3.Add Weixin-SinaWeixinPlugin [key-value] to Cordova.plist->Plugins

4.Modify project info.plist : add URL types -> URl Schemes -> Item0-'your appId' (key-value)

Usage



sina.weixin.registerApp(onSuccess,onError,appId)

在微信终端程序中注册第三方应用说明:需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。

  • appId 微信开发的ID (通过http://open.weixin.qq.com/ 申请)
  • onSuccess 注册成功时的回调函数
  • onError 注册失败时的回调函数

errCode 错误值
             errStr 错误说明
demo

  1. sina.weixin.registerApp(function(){
  2. registed=true;
  3. },onError,"XXXXXXXXX");// 填入申请的微信应用开发appId
  4. function onError(response){
  5. var detail = document.getElementById("detail");
  6. detail.innerHTML="error:"+response.errCode;
  7. detail.innerHTML=detail.innerHTML+"
  8. "+response.errStr;
  9. }

复制代码

sina.weixin.getWXAppInstallUrl(onSuccess,onError)

获取微信的itunes安装地址

  • onSuccess 获取成功时回调函数
  • onError 获取失败时回调函数

errCode 错误值
             errStr 错误说明

function onSuccess(url){ } url 为微信的itunes安装地址

function onError(error){ }
demo

  1. sina.weixin.getWXAppInstallUrl(function(resultUrl){
  2. console.log(resultUrl);
  3. },function(error){
  4. console.log(error.errCode);
  5. console.log(error.errStr);
  6. });

复制代码

sina.weixin.isWeixinInstalled(onSuccess,onError)

检查微信是否已被用户安装

  • onSuccess 微信已安装的回调函数
  • onError 微信未安装的回调函数

errCode 错误值
             errStr 错误说明

demo

  1. sina.weixin.isWeixinInstalled(function(){
  2. console.log('is installed');
  3. },function(){
  4. console.log('not installed');
  5. });
  6. sina.weixin.isSupportApi(onSuccess,onError)

复制代码

判断当前微信的版本是否支持OpenApi

  • onSuccess 当前微信版本支持OpenApi时的回调函数
  • onError 当前微信版本不支持OpenApi时的回调函数

errCode 错误值
             errStr 错误说明

demo

  1. sina.weixin.isSupportApi(function(){
  2. console.log('is support api');
  3. },function(){
  4. console.log('not support api');
  5. });

复制代码

sina.weixin.openWXApp(onSuccess,onError)

打开微信

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数

errCode 错误值
             errStr 错误说明

demo

  1. sina.weixin.openWXApp(function(){
  2. console.log('open success');
  3. },function(){
  4. console.log('open error');
  5. });

复制代码

sina.weixin.textContent(onSuccess, onError, types, text)

发送/获取 文本信息

发送:发送请求到微信,等待微信返回应答

获取:收到微信的请求,发送文本类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对文本信息的处理类型

send 表示:发送文本信息请求到微信
             get 表示:收到微信的请求,发送文本类型应答给微信

  • text 文本信息内容

demo

  1. function getTextContent() {
  2. sina.weixin.textContent(onSuccess,onError,"get","Sina App Engine");
  3. }
  4. function sendTextContent() {
  5. sina.weixin.textContent(onSuccess,onError,"send","hello world");
  6. }
  7. function onSuccess(){
  8. console.log('success');
  9. }
  10. function onError(response){
  11. var detail = document.getElementById("detail");
  12. detail.innerHTML="error:"+response.errCode;
  13. detail.innerHTML=detail.innerHTML+"
  14. "+response.errStr;
  15. }

复制代码

sina.weixin.imageContent(onSuccess, onError, types, imageUrl, options)

发送/获取 图片信息

发送:发送图片信息请求到微信,等待微信返回应答

获取:收到微信的请求,发送图片类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对图片信息的处理类型

send 表示:发送图片信息请求到微信
             get 表示:收到微信的请求,发送图片类型应答给微信

  • imageUrl 图片的Url链接
  • options 相关参数项,字典类型。包括

title
             description

demo

  1. function sendImageContent(){
  2. //从相册选择图片,并发送到微信应用
  3. var app={
  4. onCameraSuccess:function(imageURI){
  5. sina.weixin.imageContent(onSuccess,onError,"send",imageURI,{
  6. title:"kris",
  7. description:"picture",
  8. });
  9. },
  10. onCameraFail:function(msg){
  11. console.log('error msg:'+msg);
  12. },
  13. getPicture:function(){
  14. navigator.camera.getPicture(app.onCameraSuccess, app.onCameraFail, {
  15. quality: 50,
  16. destinationType: Camera.DestinationType.FILE_URI,
  17. sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
  18. saveToPhotoAlbum: false
  19. });
  20. }
  21. };
  22. app.getPicture();
  23. }
  24. function getImageContent(){
  25. //收到来自微信的请求后,发送图片应答给微信
  26. sina.weixin.getImageContent(onSuccess,onError,"http://pluginlist.sinaapp.com/client/images/music.png",{
  27. title:"kris",
  28. description:"picture",
  29. });
  30. }
  31. function onSuccess(){
  32. console.log('success');
  33. }
  34. function onError(response){
  35. var detail = document.getElementById("detail");
  36. detail.innerHTML="error:"+response.errCode;
  37. detail.innerHTML=detail.innerHTML+"
  38. "+response.errStr;
  39. }

复制代码

sina.weixin.musicContent(onSuccess, onError, types, musicUrl, options)

发送/获取 音乐信息。musicUrl和lowBandUrl不能同时为空。

发送:发送音乐信息请求到微信,等待微信返回应答

获取:收到微信的请求,发送音乐类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对音乐信息的处理类型

send 表示:发送音乐信息请求到微信
             get 表示:收到微信的请求,发送音乐类型应答给微信

  • musicUrl 音乐数据的url地址,不支持本地音乐URL。musicUrl和lowBandUrl不能同时为空。
  • options 相关参数项,字典类型。包括

title 音乐信息标题
             description 音乐信息描述内容
             lowBandUrl 音乐lowband数据的url地址,不支持本地音乐URL。musicUrl和lowBandUrl不能同时为空。
             thumbUrl 音乐信息缩略图url。当thumbUrl和thumbData同时设置时,采用thumbData。
             thumbData 音乐信息缩略图base64数据,大小不能超过32K。当thumbUrl和thumbData同时设置时,采用thumbData。

demo

  1. function sendMusicContent(){
  2. sina.weixin.musicContent(onSuccess,onError,"send",
  3. "http://pluginlist.sinaapp.com/client/music/Sunshine.mp3",
  4. {
  5. title:"Sunshine",
  6. description:"Happy Music",
  7. thumbUrl:"http://pluginlist.sinaapp.com/client/images/music.png"
  8. });
  9. }
  10. function getMusicContent(){
  11. sina.weixin.musicContent(onSuccess,onError,"get",
  12. "http://pluginlist.sinaapp.com/client/music/Sunshine.mp3",
  13. {
  14. title:"Sunshine",
  15. description:"Happy Music",
  16. thumbUrl:"http://pluginlist.sinaapp.com/client/images/music.png"
  17. });
  18. }
  19. function onSuccess(){
  20. console.log('success');
  21. }
  22. function onError(response){
  23. var detail = document.getElementById("detail");
  24. detail.innerHTML="error:"+response.errCode;
  25. detail.innerHTML=detail.innerHTML+"
  26. "+response.errStr;
  27. }

复制代码

sina.weixin.videoContent(onSuccess, onError, types, videoUrl, options)

发送/获取 视频信息。videoUrl和lowBandUrl不能同时为空。

发送:发送视频信息请求到微信,等待微信返回应答

获取:收到微信的请求,发送视频类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对视频信息的处理类型

send 表示:发送视频信息请求到微信
             get 表示:收到微信的请求,发送视频类型应答给微信

  • videoUrl 视频数据的url地址,不支持本地视频URL。videoUrl和lowBandUrl不能同时为空。
  • options 相关参数项,字典类型。包括

title 视频信息标题
             description 视频信息描述内容
             lowBandUrl 视频lowband数据的url地址,不支持本地视频URL。videoUrl和lowBandUrl不能同时为空。
             thumbUrl 视频信息缩略图url。当thumbUrl和thumbData同时设置时,采用thumbData。
             thumbData 视频信息缩略图base64数据,大小不能超过32K。当thumbUrl和thumbData同时设置时,采用thumbData。

demo

  1. function getVideoContent(){
  2. sina.weixin.videoContent(onSuccess,onError,"get",
  3. "http://www.tudou.com/listplay/0nYp1obVv60/mA_xdJq7lSo.html",
  4. {
  5. title:"video",
  6. description:"Get Happy Video",
  7. thumbUrl:"http://pluginlist.sinaapp.com/client/images/video.png"
  8. });
  9. }
  10. function sendVideoContent(){
  11. sina.weixin.videoContent(onSuccess,onError,"send",
  12. "http://www.tudou.com/listplay/0nYp1obVv60/mA_xdJq7lSo.html",
  13. {
  14. title:"video",
  15. description:"Happy Video",
  16. thumbUrl:"http://pluginlist.sinaapp.com/client/images/video.png"
  17. });
  18. }

复制代码

sina.weixin.webpageContent(onSuccess, onError, types, webpageUrl, options)

发送/获取 网页信息

发送:发送网页信息请求到微信,等待微信返回应答

获取:收到微信的请求,发送网页类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对网页信息的处理类型

send 表示:发送网页信息请求到微信
             get 表示:收到微信的请求,发送网页类型应答给微信

  • webpageUrl 网页url地址
  • options 相关参数项,字典类型。包括

title 网页信息标题
             description 网页信息描述内容
             thumbUrl 网页信息缩略图url。当thumbUrl和thumbData同时设置时,采用thumbData。
             thumbData 网页信息缩略图base64数据,大小不能超过32K。当thumbUrl和thumbData同时设置时,采用thumbData。

demo

  1. function sendWebpageContent(){
  2. sina.weixin.webpageContent(onSuccess,onError,"send",
  3. "http://sae.sina.com.cn/?m=devcenter&catId=235",
  4. {
  5. title:"新浪移动云平台介绍",
  6. description:"新浪移动云是在SAE基础上的子平台,专注于为移动设备同时提供云+端的能力。\n为方便开发者使用,移动云直接集成在SAE在线管理平台中。",
  7. thumbUrl:"http://pluginlist.sinaapp.com/client/images/icon.png"
  8. });
  9. }
  10. function getWebpageContent(){
  11. sina.weixin.webpageContent(onSuccess,onError,"get",
  12. "http://sae.sina.com.cn/?m=devcenter&catId=235",
  13. {
  14. title:"新浪移动云平台介绍",
  15. description:"新浪移动云是在SAE基础上的子平台,专注于为移动设备同时提供云+端的能力。\n为方便开发者使用,移动云直接集成在SAE在线管理平台中。",
  16. thumbUrl:"http://pluginlist.sinaapp.com/client/images/icon.png"
  17. });
  18. }

复制代码

sina.weixin.APPContent(onSuccess, onError, types, options)

发送/获取 APP扩展信息。微信需要处理这种APP扩展信息时,会调用该第三方应用的监听回调方法来处理。监听回调方法的设置及相应操作,请参考sina.weixin.setResponser(responseString)。

发送:发送APP扩展信息请求到微信,等待微信返回应答

获取:收到微信的请求,发送APP扩展类型应答给微信,并切换到微信界面

  • onSuccess 成功时的回调函数
  • onError 失败时的回调函数
  • types 设置对APP扩展信息的处理类型

send 表示:发送APP扩展信息请求到微信
             get 表示:收到微信的请求,发送APP扩展类型应答给微信

  • options 相关参数项,字典类型。包括

title APP扩展信息标题
             description APP扩展信息描述内容
             thumbUrl APP扩展信息缩略图url。当thumbUrl和thumbData同时设置时,采用thumbData。
             thumbData APP扩展信息缩略图base64数据,大小不能超过32K。当thumbUrl和thumbData同时设置时,采用thumbData。
             extInfo 自定义简单数据,长度不能超过2K。微信应用会回传给第三方应用处理。extInfo与fileData不能同时为空。
             fileData APP文件数据,JSON对象,大小不能超过10M。该数据发送给微信好友,微信好友需要点击后下载数据,微信应用会回传给第三方应用处理。extInfo与fileData不能同时为空。
             url 若第三方应用不存在,微信应用会打开该url所指的App下载地址。

demo

  1. function getAPPContent(){
  2. sina.weixin.APPContent(onSuccess,onError,"get",
  3. {
  4. title:"App消息",
  5. description:"您的App消息到啦,快去看看吧",
  6. thumbUrl:"http://pluginlist.sinaapp.com/client/images/icon.png",
  7. extInfo:"dictionary",
  8. url:"http://sae.sina.com.cn",
  9. fileData:JSON.stringify(
  10. {title:"App消息名称",
  11. description:"内容描述",
  12. thumbUrl:"缩略图链接地址"}
  13. )
  14. });
  15. }
  16. function sendAPPContent(){
  17. sina.weixin.APPContent(onSuccess,onError,"send",
  18. {
  19. title:"App消息",
  20. description:"您的App消息到啦,快去看看吧",
  21. thumbUrl:"http://pluginlist.sinaapp.com/client/images/icon.png",
  22. extInfo:"send APP",
  23. url:"http://www.sina.com.cn",
  24. fileData:JSON.stringify(
  25. {title:"App消息名称",
  26. description:"内容描述",
  27. thumbUrl:"缩略图链接地址"}
  28. )
  29. });
  30. }

复制代码

sina.weixin.setResponser(responseString)

设置监听回调函数,接收来自微信应用的请求

  • responseString 监听回调方法的名字,默认为receiveResponse

function receiveResponse(response);

  • type 回调信息的类型

0 表示显示APP扩展格式信息。
             4 表示来自微信的请求信息,获取内容后返回给微信应用。

  • 当type==0时,response还包括下面几项:

extInfo 第三方应用自定义简单数据,微信应用会回传给第三方应用处理。[说明:长度不能超过2K]
             fileData APP文件数据,JSON对象。该数据发送给微信好友,微信好友需要点击后下载数据,微信应用会回传给第三方应用处理。[说明:大小不能超过10M]
             thumbData APP扩展格式信息缩略图base64数据。

demo

  1. sina.weixin.setResponser("receiveResponse");
  2. function receiveResponse(response){
  3. if(response.type==0)
  4. {//显示来自第三方的APP扩展信息
  5. var detail = document.getElementById("detail");
  6. detail.innerHTML="extInfo:"+response.extInfo;
  7. var a=JSON.parse(response.fileData);
  8. detail.innerHTML=detail.innerHTML+"
  9. title:"+a.title;
  10. detail.innerHTML=detail.innerHTML+"
  11. description:"+a.description;
  12. detail.innerHTML=detail.innerHTML+"
  13. thumbUrl:"+a.thumbUrl;
  14. var viewport = document.getElementById('viewport');
  15. viewport.style.display = "";
  16. document.getElementById("picture").src = "data:image/jpeg;base64," + response.thumbData;
  17. }
  18. else if(response.type==4)
  19. {// 来自微信的请求信息,跳转到获取信息页面
  20. var btn1=document.getElementById("btn1");
  21. btn1.οnclick=function(){sina.weixin.textContent(onSuccess,onError,"get","Sina App Engine");};
  22. btn1.innerHTML="获取文本";
  23. }
  24. }

复制代码

PhoneGap 微信插件 for iOS相关推荐

  1. Flutter实现微信支付和iOS IAP支付

    Flutter支付 微信支付 iOS IAP应用内支付 测试IAP中断购买的测试 公司近期将收费的功能排期了,由于项目做的是线上教育,提供的服务属于虚拟物品.根据iOS官方的规定,虚拟物品交易只能使用 ...

  2. android微信支付插件,AppCan文档中心-Android微信插件接入指引

    开发者在使用APPCAN平台提供的微信插件时,需要配置相关的包名,AppID和签名.具体步骤如下(以大众版打包为例): 1. 获取apk相关的包名和签名 1.1包名 自定义包名(推荐使用) APPCA ...

  3. idea可以使用flash框架吗_这个框架厉害了,使用它几分钟就可以编写一个微信插件...

    大家好,我是章鱼猫. 今天给大家推荐的这个项目是「Wechat Spellbook」-- 一个使用 Kotlin 编写的开源微信插件框架,底层需要 Xposed 或 VirtualXposed 等 H ...

  4. 对hash签名失败_vue项目中微信jssdk在ios签名失败

    一.问题描述 1. vue项目中微信jssdk签名时,在安卓和ios是有差异的,签名时使用的url=window.location.href.split('#')[0],此时在安卓没问题,在ios会导 ...

  5. ios 上传图片失败 小程序_微信小程序ios端 使用ajaxSubmit上传图片失败,android没问题...

    微信小程序ios端 使用ajaxSubmit上传图片失败,android没问题 微信小程序开发上传图片,使用ajaxsubmit,post请求,form设置multipart/form-data, a ...

  6. P3-weixin-2.0.1 版本发布,JAVA微信插件框架

    P3-weixin-2.0.1版本发布(JAVA微信插件框架) P3-Weixin是轻量级Java插件开发框架,采用主流JAVA技术,集成强大代码生成器,增删改查一键生成,封装统一后台管理系统,不仅适 ...

  7. P3-weixin-2.0.0版本发布(微信插件式开发框架)

    P3-weixin-2.0.0版本发布(微信插件式开发框架) 1.P3-weixin为何诞生 现在微信越来越火,基于微信的公众号和服务号越来越丰富,单一的微信管家系统已经满足不了微信的需求.Jeecg ...

  8. 解决微信小程序IOS中使用picker弹出内容和手机软键盘重叠的问题

    解决微信小程序IOS中使用picker弹出内容和手机软键盘重叠的问题 项目需求: 一个信息提交页面:有input输入框,有picker选择器 遇到的问题: 点击input输入框时,手机自动弹出键盘,但 ...

  9. iOS小技能: 开发 uni 原生插件(支持iOS Extension)

    文章目录 引言 I 开发 uni-app 原生插件 1.1 SDK 包结构说明 1.2 目录格式配置 II iOS Extension(扩展) 2.1 插件作者配置 2.2 插件使用者配置 III 注 ...

最新文章

  1. 深度学习入门Fast.ai 2.0上线!自带中文字幕,所有笔记、资源全部免费!
  2. 第四次作业 孙保平034 李路平029
  3. px word 表格宽度_「Word技巧」掌握这六个Word表格处理技巧,表格排版不再是问题...
  4. [转]Win XP常遇网络故障分析:局域网问题
  5. python 螺旋数组_奇技淫巧 - Python绘制各种简单优美曲线
  6. 类加载器的理解——基于Launcher类
  7. IDEA安装插件及安装失败的处理方法
  8. c语言输出字符太阳,〖作业〗 C语言程序设计
  9. python图片马赛克_利用Python对图片进行马赛克处理
  10. Qt C++招聘要求
  11. 博途IEC TIME数据类型_基于博途V15 西门子S7-1200数据处理指令应用-移动操作
  12. GY-BMP280-3.3 高精度大气压强传感器模块
  13. 利用java对接阿里云sls服务(aliyun-log)做浏览记录
  14. 英雄联盟 python 刷等级_厉害了,30行python代码爬取英雄联盟全英雄皮肤
  15. 记我的启蒙老师谢朝晖老师
  16. java计算机毕业设计学校意见征集系统源码+系统+mysql数据库+lw文档
  17. 《金蝶ERP-K/3完全使用详解》——6.2 产品预测单
  18. 哈希(Hash)算法
  19. 文章结构层次序数(序号)的规范要求
  20. 【编程实践】Python编程手册 《Python极简教程》

热门文章

  1. hotnets2018 Networking in Heaven as on Earth 阅读报告
  2. centos mysql 1146_MySQL查询报错:ERROR 1146 (42S02): Table 'craw.sitePageConfig' doesn't exist
  3. 机器学习——特征工程——数据的标准化(Z-Score,Maxmin,MaxAbs,RobustScaler,Normalizer)
  4. 用瑞利准则研究显微镜物镜的分辨率
  5. 读《魔鬼搭讪学》有感
  6. Objective-C类别(catagory)
  7. 基于python的 ping 网络状态监测方法 亲测有效
  8. 思科网院 Routing and Switching Essentials ( 版本 6.00) - RSE 6.0 第 1 章考试答案
  9. Android 开发技术周报
  10. Iron WebScraper 网络爬虫