wechat/base
base module provides frequently used miniprogram APIs extend them as much as one needs, all wechat bindings are asynchronous and returns a Promise
Types
Values
pub fn add_phone_contact(
first_name f: String,
mobile_phone_number mp: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.addPhoneContact
Add a contact to the phone book
pub fn check_session(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.checkSession
pub fn choose_contact(
phone_number p: Bool,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.chooseContact
Select a contact from the phone book
pub fn clear_storage(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.clearStorage
pub fn get_background_fetch_data(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getBackgroundFetchData
Get background fetch data
pub fn get_background_fetch_token(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getBackgroundFetchToken
Get background fetch token
pub fn get_clipboard(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getClipboardData
pub fn get_file_info(
path p: String,
digest_algorithm a: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getFileInfo
pub fn get_privacy_contract(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getPrivacyContract
pub fn get_privacy_setting(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getPrivacySetting
pub fn get_random_values(length l: Int) -> object.JsObject
Encryption (Random)
wx.getRandomValues
Get cryptographically secure random numbers
pub fn get_saved_file_list(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getSavedFileList
pub fn get_setting(
subscriptions s: Bool,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getSetting
pub fn get_storage(
key k: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getStorage
pub fn get_storage_info(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getStorageInfo
pub fn get_system_info(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.getSystemInfo
pub fn get_update_manager() -> object.JsObject
wx.getUpdateManager
Get update manager for app updates
pub fn get_user_crypto_manager() -> object.JsObject
User Crypto Manager
wx.getUserCryptoManager
Get user crypto manager
pub fn hide_loading(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.hideLoading
pub fn hide_tabbar(
animation a: Bool,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.hideTabbar
pub fn login(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.login
pub fn navigate_back(
by delta: Int,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.navigateBack
pub fn navigate_to(
to url: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.navigateTo
pub fn on_background_fetch_data(
callback cb: fn(object.JsObject) -> Nil,
) -> Nil
wx.onBackgroundFetchData
Listen for background fetch data event
pub fn open_document(
path p: String,
of t: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.openDocument
pub fn pre_download_subpackage(
root_dir rd: String,
name n: String,
) -> object.JsObject
Subpackage Pre-download
wx.preDownloadSubpackage
Pre-download subpackage
pub fn relaunch(
to url: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.reLaunch
pub fn remove_saved_file(
file_path fp: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.removeSavedFile
pub fn remove_storage(
key k: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.removeStorage
pub fn request(
method m: String,
url u: String,
header h: object.JsObject,
data d: object.JsObject,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.request
pub fn request_payment(
time_stamp t: String,
nonce_str n: String,
pkg p: String,
sign_type s: String,
pay_sign ps: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.requestPayment
pub fn router_add_route_builder(
router r: object.JsObject,
name n: String,
builder b: object.JsObject,
) -> Nil
Router.addRouteBuilder Add route builder
pub fn router_get_route_context(
router r: object.JsObject,
) -> object.JsObject
Router.getRouteContext Get route context
pub fn router_remove_route_builder(
router r: object.JsObject,
name n: String,
) -> Nil
Router.removeRouteBuilder Remove route builder
pub fn save_file(
path p: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.saveFile
pub fn scan_code(
scan_type st: List(String),
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.scanCode
Scan the QR code
pub fn set_background_fetch_token(token t: String) -> Nil
Background Fetch
wx.setBackgroundFetchToken
Set background fetch token
pub fn set_clipboard(
data d: object.JsObject,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.setClipboardData
pub fn set_navigation_bar(
title t: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.setNavigationBarTitle
pub fn set_storage(
key k: String,
value v: object.JsObject,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.setStorage
pub fn show_loading(
title t: String,
mask m: Bool,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.showLoading
pub fn show_tabbar(
animation a: Bool,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.showTabbar
pub fn show_toast(
title t: String,
icon i: String,
mask m: Bool,
duration d: Int,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.showToast
pub fn switch_tab(
to url: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.switchTab
pub fn to_payment(p: String) -> Int
utility function convert string to wechat payment
Examples
> to_payment("2.9")
290
> to_payment("129.013")
12901
pub fn update_manager_apply_update(um: object.JsObject) -> Nil
UpdateManager.applyUpdate
Apply the update and restart
pub fn update_manager_on_check_for_update(
um: object.JsObject,
callback cb: fn(object.JsObject) -> Nil,
) -> Nil
UpdateManager.onCheckForUpdate
Listen for update check event
pub fn update_manager_on_update_failed(
um: object.JsObject,
callback cb: fn(object.JsObject) -> Nil,
) -> Nil
UpdateManager.onUpdateFailed
Listen for update failed event
pub fn update_manager_on_update_ready(
um: object.JsObject,
callback cb: fn(object.JsObject) -> Nil,
) -> Nil
UpdateManager.onUpdateReady
Listen for update ready event
pub fn upload_file(
to url: String,
path p: String,
header h: object.JsObject,
form f: object.JsObject,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.uploadFile
pub fn user_crypto_manager_get_latest_user_key(
manager m: object.JsObject,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
UserCryptoManager.getLatestUserKey Get latest user key
pub fn user_crypto_manager_get_random_values(
manager m: object.JsObject,
length l: Int,
) -> object.JsObject
UserCryptoManager.getRandomValues Get random values from crypto manager
pub fn vibrate_long(
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.vibrateLong
pub fn vibrate_short(
of t: String,
complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
wx.vibrateShort
pub fn ymd(
d: Date,
) -> promise.Promise(Result(object.JsObject, object.WechatError))
utility function to convert Date to local YYYY-MM-DD
asynchronous, a test is written as showcase