if (my.canIUse('createWebViewContext')) {
this.webViewContext = my.createWebViewContext('web-view-1');
} else {
my.alert({
title: '提示',
content: '当前支付宝版本过低,无法使用此功能,请升级最新版本支付宝'
});
}
const updateManager = my.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
my.confirm({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
})
冷启动: 用户打开未启动或者已经销毁的小程序,称为冷启动。小程序执行初始化,触发onLaunch回调函数。
热启动: 用户打开已经关闭但仍处于后台运行的小程序,成为热启动。小程序不会重启,只是从后台切到前台,触发onShow回调函数,不会触发onLaunch函数。当前运行页面的的onShow函数也会被触发。
// 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。
const options = my.getEnterOptionsSync()
console.log(options)
App({
globalData: {
params: {}
},
onLaunch(options){
},
onShow(options){
}
})
let app = getApp();
console.log(app.globalData);
my.postMessage({'sendToMiniProgram': '0'});
<web-view id="web-view-1" src="{{url}}" onMessage="onmessage"></web-view>
this.webViewContext = my.createWebViewContext('web-view-1');
onmessage(e){
if(e.detail.sendToMiniProgram === '0'){
my.getAuthCode({
scopes: 'auth_base',
success: (res) => {
this.webViewContext.postMessage({ 'authCode': res.authCode });
},
});
}
},
// 直接在当前页面上打开小程序
alipays://platformapi/startapp?appId=xxx&page=pages/index/index&query=
// 会跳转到支付宝的一个页面再打开
https://ds.alipay.com/?scheme=alipays://platformapi/startapp?appId=xxx&page=pages/index/index&query=
const fs = require("fs");
const path = require('path');
const AlipaySdk = require('alipay-sdk').default;
const alipaySdk = new AlipaySdk({
appId: 'xxxxx',
privateKey: fs.readFileSync(path.join(__dirname, '/pem/private-key.pem'), 'ascii'),
alipayPublicKey: fs.readFileSync(path.join(__dirname, '/pem/alipayPublic-key.pem'), 'ascii')
});
let options = {
validateSign: true
};
let getUserInfoMethod = 'alipay.system.oauth.token';
let params2 = {
charset: 'UTF-8',
sign_type: 'RSA2',
timestamp: '2014-07-24 03:07:50',
version: '1.0',
grantType: 'authorization_code',
code:'xxx'
};
alipaySdk.exec(getUserInfoMethod, params2, options).then(result => {
console.log("alipay.system.oauth.token-------");
console.log(result);
}).catch(err=>{
console.log("alipay.system.oauth.token error-------");
console.log(err);
})