4.x 版本适配了最新的微信SDK和Cordova,由BSF软件基金会运营维护,点击了解
Debido a la actualización de seguridad de la versión del sistema iOS 13, el SDK oficial de WeChat se ha adaptado desde 1.8.6 con soporte para saltos en modo *Enlaces universales* y verificación de validez al compartir.
Desde la versión 3.0.0 de nuestro complemento, cambiamos al último SDK de WeChat. Antes de usarlo, debe configurar el servicio Universal Links y prestar atención a pasar la variable universallink
al instalar el complemento; de lo contrario, no funcionará correctamente.
Si no desea utilizar las funciones de la nueva versión, puede recurrir a la versión 3.0.0 anterior.
Un complemento de Cordova, una versión JS de Wechat SDK
文档 · 教程 · Preguntas frecuentes · DEMO
cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID --variable universallink=YOUR_UNIVERSAL_LINK
cordova build ios
cordova build android
Wechat . isInstalled ( function ( installed ) {
alert ( "Wechat installed: " + ( installed ? "Yes" : "No" ) ) ;
} , function ( reason ) {
alert ( "Failed: " + reason ) ;
} ) ;
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 ) ;
} ) ;
Wechat . share ( {
text : "This is just a plain string" ,
scene : Wechat . Scene . TIMELINE // share to Timeline
} , function ( ) {
alert ( "Success" ) ;
} , function ( reason ) {
alert ( "Failed: " + reason ) ;
} ) ;
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 ) ;
} ) ;
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 ) ;
} ) ;
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 ) ;
} ) ;
// See https://github.com/xu-li/cordova-plugin-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 ) ;
} ) ;
//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' ) ;
} )
//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' ) ;
} )
Wechat . isInstalled ( ( installed ) => {
if ( ! installed ) return
document . addEventListener (
'wechat.launchFromWX' ,
( { extinfo } ) => {
console . log ( 'launch from wechat extinfo = ' , extinfo )
} ,
false
)
} )
Para más uso, consulte https://jasonz1987.github.io/cordova-wechat-docs/docs/usages
QQ群:190808518
Necesitamos su apoyo para mejorar el software de código abierto. Si inducimos su tiempo de desarrollo, bienvenido a donarnos.
LICENCIA MIT