### Installing Specific Third-Party Library Example Source: https://developers.weixin.qq.com/miniprogram/dev/devtools/minitest/upload_case Example command to install the 'python-dateutil' library into the 'minitest_lib' directory, specifying it as a required library for cloud testing. ```bash pip3 install python-dateutil -t minitest_lib --no-deps -I ``` -------------------------------- ### Initial Dockerfile Example Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/scene/build/speed This is an initial Dockerfile example that may lead to longer build times and occasional errors. It installs Python and dependencies from default sources. ```docker FROM alpine:3.14 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories && apk add --update --no-cache python3 py3-pip && rm -rf /var/cache/apk/* ENV TZ Asia/Shanghai RUN apk add tzdata && cp /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone RUN apk add ca-certificates COPY . /app WORKDIR /app RUN pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple && pip config set global.trusted-host mirrors.cloud.tencent.com && pip install --upgrade pip && pip install --user -r requirements.txt EXPOSE 80 CMD ["python3", "run.py", "0.0.0.0", "80"] ``` -------------------------------- ### Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_getpubnewtemplatetitles.html An example of a GET request to the API, showing specific values for access token, category IDs, start index, and limit. ```HTTP https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=ACCESS_TOKEN&ids="2,616"&start=0&limit=1 ``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/scene/deploy/github-actions.html Sets up a new project directory, initializes npm, installs Eleventy, and creates essential project files like README and .gitignore. ```bash mkdir wxcloud-static-demo cd wxcloud-static-static-demo npm init -y # Install Eleventy npm install --save-dev @11ty/eleventy # Generate README.md echo '# Weixin Cloud Run Static Storage Demo' > README.md # Generate .gitignore echo 'node_modules' > .gitignore ``` -------------------------------- ### HTTPS GET Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/operation/api_getversionlist This is an example of how to make an HTTPS GET request to the Get Client Version API. ```HTTP GET https://api.weixin.qq.com/wxaapi/log/get_client_version?access_token=ACCESS_TOKEN ``` -------------------------------- ### Full Example with Cloud Hosting Initialization Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/development/storage/h5/delete This example shows how to initialize the Cloud SDK within an HTML file for use with Cloud Hosting. It requires authentication and specifies the AppID and environment ID. ```html ``` -------------------------------- ### HTTPS Call Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/mp-message-management/subscribe-message/api_getpubnewtemplatetitles.html Demonstrates how to make an HTTPS GET request to retrieve public template titles. Ensure you replace ACCESS_TOKEN, IDS, START, and LIMIT with your actual values. ```HTTP GET https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=ACCESS_TOKEN&ids=IDS&start=START&limit=LIMIT ``` -------------------------------- ### Project Configuration Example Source: https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig A comprehensive example of a project configuration file, including settings for root directories, build tools, and various options like packOptions and debugOptions. ```json { "miniprogramRoot": "./src", "qcloudRoot": "./svr", "setting": { "postcss": true, "es6": true, "minified": true, "urlCheck": false, "checkSiteMap": true, "enhance": true, "babelSetting": { "ignore": [ "utils/something_not_to_process.js", "miniprogram_npm/*", "utils/already_handle/*" ] } }, "packOptions": { "ignore": [] }, "debugOptions": {} } ``` -------------------------------- ### PHP CURL Request to Cloud Run Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/development/call/client Implement a GET request to a Cloud Run service using PHP's cURL library. This example shows basic cURL setup and execution. ```php 'https://demo.ap-shanghai.run.tcloudbase.com', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', )); $response = curl_exec($curl); curl_close($curl); echo $response; ``` -------------------------------- ### Example Request for Get User Encrypt Key Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/user-info/internet/api_getuserencryptkey.html An example of a GET request to the getUserEncryptKey API, demonstrating the required query parameters. ```HTTP GET https://api.weixin.qq.com/wxa/business/getuserencryptkey?access_token=OsAoOMw4niuuVbfSxxxxxxxxxxxxxxxxxxx&signature=fefce01bfba4670c85b228e6ca2b493c90971e7c442f54fc448662eb7cd72509&openid=oGZUI0egBJY1zhBYw2KhdUfwVJJE&sig_method=hmac_sha256 ``` -------------------------------- ### App Configuration Example Source: https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html This is a comprehensive example of the app.json configuration file, demonstrating various settings like pages, window properties, tab bar setup, and network timeouts. Ensure all paths and text are correctly defined for your application. ```json { "pages": ["pages/index/index", "pages/logs/index"], "window": { "navigationBarTitleText": "Demo" }, "tabBar": { "list": [ { "pagePath": "pages/index/index", "text": "首页" }, { "pagePath": "pages/logs/logs", "text": "日志" } ] }, "networkTimeout": { "request": 10000, "downloadFile": 10000 }, "debug": true } ``` -------------------------------- ### B2b Get Refund Response Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/B2b/bill/api_getrefund Example of a successful response from the B2b Get Refund API, detailing refund information. ```JSON { "refund_id": "r202307281444591411763685", "out_refund_no": "12177525012014070332321235", "order_id": "o202307291423123564754773", "out_trade_no": "1217752501201407033233368018", "create_time": "2023-07-30 17:04:23", "refund_time": "2023-07-30 17:04:28", "refund_status": "REFUND_SUCC", "amount": { "order_amount": 1300, "refund_amount": 100, "currency": "CNY" }, "wxpay_refund_id": "1235481444591411763685", "reverse_sett_state": 3, "refund_channel_info": { "channel": "ORIGINAL", "user_received_account": "招商银行借记卡0000", "funds_account": "UNAVAILABLE" }, "description":"", "errcode": 0, "errmsg": "OK" } ``` -------------------------------- ### Google Play Billing API Usage Example Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/api/miniapp/GooglePlayBilling.html This example demonstrates how to use the Google Play Billing API, including starting the connection, handling purchase updates, querying product details, launching the billing flow, and consuming purchases. It requires prior setup and understanding of Google Play's billing documentation. ```javascript onLoad() { this.startConnection(); const onMethod = (res) => { console.log('onPurchasesUpdatedMethod', res) if (res.responseCode == 0) { const purchases = res.purchases for (let i = 0; i < purchases.length; i++) { const purchase = purchases[i] console.log('purchase', purchase) const purchaseToken = purchase.token || purchase.purchaseToken this.consumeAsync(purchaseToken) // 拿到 token 之后再验证 } } else { console.error('err', res.responseCode, res.debugMessage) // 根据错误码自行处理 https://developer.android.com/google/play/billing/errors?hl=zh-cn } } wx.miniapp.GooglePlayBilling.onPurchasesUpdatedMethod(onMethod) }, startConnection() { wx.miniapp.GooglePlayBilling.startConnection({ success: (res) => { console.log("Connection started successfully", res); this.queryProductDetails(); }, fail: (err) => { console.error("Failed to start connection", err); }, complete(res) { console.error("GooglePlayBilling.startConnection", res) } }) }, queryProductDetails() { wx.miniapp.GooglePlayBilling.queryProductDetails({ productList: [ { productId: 'your_product_id', productType: 'INAPP', //SUBS 或者 INAPP }, ], complete(res) { console.error("GooglePlayBilling.queryProductDetails", res) } }) }, launchBillingFlow() { wx.miniapp.GooglePlayBilling.launchBillingFlow({ productId: 'your_product_id', productType: 'INAPP', //SUBS 或者 INAPP complete(res) { console.error("GooglePlayBilling.launchBillingFlow", res) } }) }, consumeAsync(purchaseToken) { wx.miniapp.GooglePlayBilling.consumeAsync({ purchaseToken, complete(res) { console.error("GooglePlayBilling.consumeAsync", res) } }) } ``` -------------------------------- ### Basic Animation Setup and Playback Source: https://developers.weixin.qq.com/miniprogram/dev/api/ui/animation/Animation.html This snippet demonstrates how to create an animation instance, apply sequential transformations (scale, rotate, then translate), and update the view. It shows the use of `wx.createAnimation`, `step()`, and `export()` for applying animations. The `setTimeout` function is used to chain animations with a delay. ```javascript Page({ data: { animationData: {} }, onShow: function(){ var animation = wx.createAnimation({ duration: 1000, timingFunction: 'ease', }) this.animation = animation animation.scale(2,2).rotate(45).step() this.setData({ animationData:animation.export() }) setTimeout(function() { animation.translate(30).step() this.setData({ animationData:animation.export() }) }.bind(this), 1000) }, rotateAndScale: function () { // 旋转同时放大 this.animation.rotate(45).scale(2, 2).step() this.setData({ animationData: this.animation.export() }) }, rotateThenScale: function () { // 先旋转后放大 this.animation.rotate(45).step() this.animation.scale(2, 2).step() this.setData({ animationData: this.animation.export() }) }, rotateAndScaleThenTranslate: function () { // 先旋转同时放大,然后平移 this.animation.rotate(45).scale(2, 2).step() this.animation.translate(100, 100).step({ duration: 1000 }) this.setData({ animationData: this.animation.export() }) } }) ``` ```html ``` -------------------------------- ### Full Configuration Example in app.json Source: https://developers.weixin.qq.com/miniprogram/dev/framework/ability/darkmode Example of `app.json` configuration for Dark Mode, including window and tab bar properties that can be customized with theme variables. ```json { "window": { "navigationBarBackgroundColor": "@navBgColor", "navigationBarTextStyle": "@navTxtStyle", "backgroundColor": "@bgColor", "backgroundTextStyle": "@bgTxtStyle", "backgroundColorTop": "@bgColorTop", "backgroundColorBottom": "@bgColorBottom" }, "tabBar": { "color": "@tabFontColor", "selectedColor": "@tabSelectedColor", "backgroundColor": "@tabBgColor", "borderStyle": "@tabBorderStyle", "list": [{ "iconPath": "@iconPath1", "selectedIconPath": "@selectedIconPath1" }, { "iconPath": "@iconPath2", "selectedIconPath": "@selectedIconPath2" }] } } ``` -------------------------------- ### HTTPS GET Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/operation/api_getgrayreleaseplan.html This is an example of how to make an HTTPS GET request to the getGrayReleasePlan API. Ensure you replace ACCESS_TOKEN with a valid token. ```HTTP GET https://api.weixin.qq.com/wxa/getgrayreleaseplan?access_token=ACCESS_TOKEN ``` -------------------------------- ### Example Usage Source: https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.html Example code demonstrating how to initialize and use the BackgroundAudioManager to play audio. ```javascript const backgroundAudioManager = wx.getBackgroundAudioManager() backgroundAudioManager.title = '此时此刻' backgroundAudioManager.epname = '此时此刻' backgroundAudioManager.singer = '许巍' backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000' // Playback starts automatically after setting src backgroundAudioManager.src = 'https://wx_test.mp3' ``` -------------------------------- ### ext.json Configuration Example Source: https://developers.weixin.qq.com/miniprogram/dev/devtools/ext A comprehensive example of an ext.json file, demonstrating all configuration options for integrating extAppid development. ```json { "extEnable": true, "extAppid": "wxf9c4501a76931b33", "directCommit": false, "ext": { "name": "wechat", "attr": { "host": "open.weixin.qq.com", "users": [ "user_1", "user_2" ] } }, "extPages": { "pages/logs/logs": { "navigationBarTitleText": "logs" } }, "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Demo", "navigationBarTextStyle":"black" }, "tabBar": { "list": [{ "pagePath": "pages/index/index", "text": "首页" }, { "pagePath": "pages/logs/logs", "text": "日志" }] }, "networkTimeout": { "request": 10000, "downloadFile": 10000 }, "plugins": { "myPlugin": { "version": "1.0.0", "provider": "wxidxxxxxxxxxxxxxxxx" } } } ``` -------------------------------- ### B2b Get Refund Request Payload Examples Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/B2b/bill/api_getrefund Examples of request payloads for the B2b Get Refund API. You can query using either `out_refund_no` or `refund_id`. ```JSON { "mchid": "1230000109", "out_refund_no": "12177525012014070332321235" } ``` ```JSON { "mchid": "1230000109", "refund_id": "r202307281444591411763685" } ``` -------------------------------- ### Share File Example Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/api/miniapp/shareFile.html This example demonstrates how to download a file and then share it using the wx.miniapp.shareFile API. It includes success and failure callbacks for both download and share operations. Ensure the file path is a local path. ```javascript wx.downloadFile({ url: 'https://dldir1.qq.com/WechatWebDev/test/redhood/test.docx', filePath: wx.env.USER_DATA_PATH + '/test.docx', success(res) { console.log('download file success', res) console.log('share file') wx.miniapp.shareFile({ filePath: res.filePath, success(res) { console.log('share file success', res) }, fail(res) { console.log('share file fail', res) } }) }, fail(res) { console.log('download file fail', res) } }) ``` -------------------------------- ### B2b Get Order Response Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/B2b/bill/api_getorder.html Example of a successful response from the B2b Get Order API, detailing order status, payment information, and amounts. ```JSON { "appid": "wx8888888888888888", "mchid": "1230000109", "out_trade_no": "1217752501201407033233368018", "order_id": "o202307291423123564754773", "pay_status": "ORDER_PAY_SUCC", "pay_time": "2023-07-20 17:04:28", "attach": "", "payer_openid": "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o", "amount": { "order_amount": 1, "payer_amount": 1, "currency": "CNY", }, "wxpay_transaction_id": "2123191423123564754773", "env": 0 "errcode": 0, "errmsg": "OK" } ``` -------------------------------- ### B2b Get Order Request Payload Examples Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/B2b/bill/api_getorder.html Examples of request payloads for the B2b Get Order API. You can query using either `out_trade_no` or `order_id`. ```JSON { "mchid": "1230000109", "out_trade_no": "1217752501201407033233368018" } ``` ```JSON { "mchid": "1230000109", "order_id": "o202307291423123564754773" } ``` -------------------------------- ### Install kbone-cli Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/kbone/index Install the kbone-cli globally to quickly create new projects. This command is used for setting up the development environment. ```bash npm install -g kbone-cli ``` -------------------------------- ### Drawing a Quadratic Bézier Curve Source: https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.quadraticCurveTo.html This example demonstrates how to draw a quadratic Bézier curve using `quadraticCurveTo`. It also shows how to draw guide points and lines to visualize the curve's start, control, and end points. Note that `CanvasContext` is a legacy API. ```javascript const ctx = wx.createCanvasContext('myCanvas') // Draw points ctx.beginPath() ctx.arc(20, 20, 2, 0, 2 * Math.PI) ctx.setFillStyle('red') ctx.fill() ctx.beginPath() ctx.arc(200, 20, 2, 0, 2 * Math.PI) ctx.setFillStyle('lightgreen') ctx.fill() ctx.beginPath() ctx.arc(20, 100, 2, 0, 2 * Math.PI) ctx.setFillStyle('blue') ctx.fill() ctx.setFillStyle('black') ctx.setFontSize(12) // Draw guides ctx.beginPath() ctx.moveTo(20, 20) ctx.lineTo(20, 100) ctx.lineTo(200, 20) ctx.setStrokeStyle('#AAAAAA') ctx.stroke() // Draw quadratic curve ctx.beginPath() ctx.moveTo(20, 20) ctx.quadraticCurveTo(20, 100, 200, 20) ctx.setStrokeStyle('black') ctx.stroke() ctx.draw() ``` -------------------------------- ### Full Theme Configuration Example in theme.json Source: https://developers.weixin.qq.com/miniprogram/dev/framework/ability/darkmode Complete `theme.json` example defining light and dark mode variables for various UI elements including navigation, background, and tab bar. ```json { "light": { "navBgColor": "#f6f6f6", "navTxtStyle": "black", "bgColor": "#ffffff", "bgTxtStyle": "light", "bgColorTop": "#eeeeee", "bgColorBottom": "#efefef", "tabFontColor": "#000000", "tabSelectedColor": "#3cc51f", "tabBgColor": "#ffffff", "tabBorderStyle": "black", "iconPath1": "image/icon1_light.png", "selectedIconPath1": "image/selected_icon1_light.png", "iconPath2": "image/icon2_light.png", "selectedIconPath2": "image/selected_icon2_light.png", }, "dark": { "navBgColor": "#191919", "navTxtStyle": "white", "bgColor": "#1f1f1f", "bgTxtStyle": "dark", "bgColorTop": "#191919", "bgColorBottom": "#1f1f1f", "tabFontColor": "#ffffff", "tabSelectedColor": "#51a937", "tabBgColor": "#191919", "tabBorderStyle": "white", "iconPath1": "image/icon1_dark.png", "selectedIconPath1": "image/selected_icon1_dark.png", "iconPath2": "image/icon2_dark.png", "selectedIconPath2": "image/selected_icon2_dark.png", } } ``` -------------------------------- ### Complete File Download Example with Progress and Saving Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/development/storage/miniapp/download This comprehensive example shows how to download a file, monitor its progress, optionally abort the download, and then save the downloaded file locally. It includes a reusable `downloadFile` function. ```javascript Page({ async onLoad() { const result = await this.downloadFile('cloud://test.png',function(res){ console.log(`下载进度:${res.progress}%,已下载${res.totalBytesWritten}B,共${res.totalBytesExpectedToWrite}B`) // if(res.progress > 50){ // 测试文件下载一半就终止下载 // return false // } }) wx.saveFile({ tempFilePath: result.tempFilePath }).then(console.log) }, /** * 下载微信云托管对象存储到本地 * @param {*} fileID 对象存储文件ID * @param {*} onCall 上传回调,文件上传过程监听,返回false时会中断上传 */ downloadFile(fileID, onCall = () => {}) { return new Promise((resolve, reject) => { const task = wx.cloud.downloadFile({ fileID, success: res => resolve(res), fail: e => { const info = e.toString() if (info.indexOf('abort') != -1) { reject(new Error('【文件下载失败】中断下载')) } else { reject(new Error('【文件下载失败】网络或其他错误')) } } }) task.onProgressUpdate((res) => { if (onCall(res) == false) { task.abort() } }) }) } }) ``` -------------------------------- ### HTTPS Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/livebroadcast/studio-management/api_getassistantlist.html This is an example of how to make an HTTPS GET request to the getAssistantList API. ```HTTP GET https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist?access_token=ACCESS_TOKEN ``` -------------------------------- ### Create Project Directory Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/quickstart/custom/python Use CLI commands to create a new project directory named 'hello' and navigate into it. ```bash mkdir hello cd hello ``` -------------------------------- ### HTTPS Request Example for Get User Portrait Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/data-analysis/others/api_getuserportrait.html This is an example of the JSON payload to send when making an HTTPS request to the Get User Portrait API. It specifies the date range for the data retrieval. ```json { "begin_date": "20170611", "end_date": "20170617" } ``` -------------------------------- ### Initialize a New Kbone Project Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/kbone/index Use the kbone-cli to initialize a new project named 'my-app'. This command scaffolds a new project structure for development. ```bash kbone init my-app ``` -------------------------------- ### Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/operation/api_getfeedback Example of a GET request to the feedback list API, specifying pagination parameters. ```HTTP GET https://api.weixin.qq.com/wxaapi/feedback/list?access_token=ACCESS_TOKEN&page=1&num=10 ``` -------------------------------- ### Open Business Webview Example Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/api/miniapp/OpenBusinessWebview.html This snippet demonstrates how to use the wx.miniapp.openBusinessWebview API to initiate the App signing process. It includes success and failure callbacks for user feedback. ```javascript wx.miniapp.openBusinessWebview({ preEntrustwebId: '5778aadxxxx', success(res) { wx.showToast({ title: '成功', }) }, fail() { wx.showToast({ title: '失败', }) } }) ``` -------------------------------- ### Response Payload Example (Error) Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/immediate-delivery/deliver-by-business/api_getlocalorder.html Example of an error response from the Get Local Order API. ```JSON { "errcode": 930563, "errmsg": "order not exists" } ``` -------------------------------- ### Install wx-cloud-client-sdk via npm Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloud/guide/model/init-sdk Install the SDK package in your Mini Program's directory using npm. After installation, build the npm dependencies using the WeChat DevTools. ```bash npm install @cloudbase/wx-cloud-client-sdk --save ``` -------------------------------- ### Go HTTP Get Example for Open Interface Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/guide/weixin/open Example of making an HTTP GET request using Go's standard http package to the Weixin Open Interface. This is a reference for Go developers. ```go resp, err := http.Get("http://api.weixin.qq.com/wxa/getwxadevinfo") ``` -------------------------------- ### Choose Media Example Source: https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseMedia.html Demonstrates how to use wx.chooseMedia to select up to 9 images or videos from the album or camera. It logs the temporary file path and size of the first selected file upon success. ```javascript wx.chooseMedia({ count: 9, mediaType: ['image','video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success(res) { console.log(res.tempFiles[0].tempFilePath) console.log(res.tempFiles[0].size) } }) ``` -------------------------------- ### HTTPS GET Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/charge/api_getrecentaverageusage.html This is an example of how to make an HTTPS GET request to the getRecentAverageUsage API endpoint. Ensure you replace ACCESS_TOKEN with a valid access token and spuId with the correct product SPU ID. ```HTTP GET https://api.weixin.qq.com/wxa/charge/usage/get_recent_average?access_token=ACCESS_TOKEN&spuId=10000077 ``` -------------------------------- ### Get Comment Info Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/transaction-guarantee/comment/api_getcommentinfo.html Example of an HTTP GET request to retrieve comment information. Ensure you replace placeholder values like '123456' and 'xxxxxx' with actual comment IDs and access tokens. ```HTTP GET https://api.weixin.qq.com/wxaapi/comment/commentinfo/get?commentId=123456&access_token=xxxxxx ``` -------------------------------- ### Basic Node.js Dockerfile Example Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/scene/build/speed A fundamental Dockerfile for a Node.js application, illustrating the steps to install Node.js, copy code, install dependencies, and run the application. ```shell # Install an alpine system, any version FROM alpine:3.15 # Then download and install Node.js on the alpine system RUN apk add --update --no-cache nodejs npm # Copy our code to a directory on the server COPY . . # npm install project dependencies RUN npm install # Start the project using the start command CMD ["node", "index.js"] ``` -------------------------------- ### Full Example for Official Account H5 Download Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/development/storage/h5/download This comprehensive example shows how to initialize the CloudBase SDK and download a file within an HTML file for browser execution. It requires authentication and specific environment configurations. ```html ``` -------------------------------- ### Request Payload Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/immediate-delivery/deliver-by-business/api_getlocalorder.html Example of the JSON payload required for the Get Local Order API request. ```JSON { "shopid": "a6c91f6f857f4d488e689xxxxx", "shop_order_id": "61ac7ab5d5a12c5xxxxxx", "shop_no": "gaga001xxx", "delivery_sign": "f7d21b90d8194eeab4b74ef3428xxxxxzx" } ``` -------------------------------- ### Open Bluetooth Adapter Example Source: https://developers.weixin.qq.com/miniprogram/dev/framework/usability/PublicErrno.html Demonstrates how to use wx.openBluetoothAdapter and handle potential errors, including checking for the specific errno. ```javascript wx.openBluetoothAdapter({ success (res) { console.log(res) }, fail (err) { console.log(err.errno) } }) ``` -------------------------------- ### HTTPS Response Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/data-analysis/others/api_getvisitdistribution Example of a successful response from the Get Visit Distribution API via HTTPS. ```json { "ref_date": "20170313", "list": [ { "index": "access_source_session_cnt", "item_list": [ { "key": 10, "value": 5 }, { "key": 8, "value": 687 }, { "key": 7, "value": 10740 }, { "key": 6, "value": 1961 }, { "key": 5, "value": 677 }, { "key": 4, "value": 653 }, { "key": 3, "value": 1120 }, { "key": 2, "value": 10243 }, { "key": 1, "value": 116578 } ] }, { "index": "access_staytime_info", "item_list": [ { "key": 8, "value": 16329 }, { "key": 7, "value": 19322 }, { "key": 6, "value": 21832 }, { "key": 5, "value": 19539 }, { "key": 4, "value": 29670 }, { "key": 3, "value": 19667 }, { "key": 2, "value": 11794 }, { "key": 1, "value": 4511 } ] }, { "index": "access_depth_info", "item_list": [ { "key": 5, "value": 217 }, { "key": 4, "value": 3259 }, { "key": 3, "value": 32445 }, { "key": 2, "value": 63542 }, { "key": 1, "value": 43201 } ] } ] } ``` -------------------------------- ### HTTPS Response Example for Get User Portrait Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/data-analysis/others/api_getuserportrait.html This is an example of the JSON response received from the Get User Portrait API. It includes detailed user statistics broken down by province, city, gender, platform, device, and age. ```json { "ref_date": "20170611", "visit_uv_new": { "province": [ { "id": 31, "name": "广东省", "value": 215 } ], "city": [ { "id": 3102, "name": "广州", "value": 78 } ], "genders": [ { "id": 1, "name": "男", "value": 2146 } ], "platforms": [ { "id": 1, "name": "iPhone", "value": 27642 } ], "devices": [ { "name": "OPPO R9", "value": 61 } ], "ages": [ { "id": 1, "name": "17岁以下", "value": 151 } ] }, "visit_uv": { "province": [ { "id": 31, "name": "广东省", "value": 1341 } ], "city": [ { "id": 3102, "name": "广州", "value": 234 } ], "genders": [ { "id": 1, "name": "男", "value": 14534 } ], "platforms": [ { "id": 1, "name": "iPhone", "value": 21750 } ], "devices": [ { "name": "OPPO R9", "value": 617 } ], "ages": [ { "id": 1, "name": "17岁以下", "value": 3156 } ] } } ``` -------------------------------- ### Command-Line Preview Source: https://developers.weixin.qq.com/miniprogram/dev/devtools/ci Use this command to preview your miniprogram. Specify project path, private key, app ID, and version. Options include QR code format and output destination. ```bash miniprogram-ci \ preview \ --pp ./demo-proj/ \ --pkp ./private.YOUR_APPID.key \ --appid YOUR_APPID \ --uv PACKAGE_VERSION \ -r 1 \ --enable-es6 true \ --proxy YOUR_PROXY \ --qrcode-format image \ --qrcode-output-dest '/tmp/x.jpg' \ ``` -------------------------------- ### Get Device List API Request Example Source: https://developers.weixin.qq.com/miniprogram/dev/devtools/minitest/api_device.html This example demonstrates how to make a GET request to the device_list API endpoint. Ensure you replace placeholder values with your actual token and group_en_id. The API is only available for paid projects. ```HTTP GET https://minitest.weixin.qq.com/thirdapi/device_list?token=YOUR_TOKEN&group_en_id=YOUR_GROUP_EN_ID ``` -------------------------------- ### Complete Example for H5 Environment Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/development/storage/h5/gettempurl This example demonstrates how to initialize the cloud SDK and fetch temporary file URLs within an HTML file for a WeChat Official Account H5 environment. It requires authentication and proper configuration of AppIDs and environment IDs. ```html ``` -------------------------------- ### Resolve 'createAssetsCar failed' IPA Build Error Source: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/troubleshooting/dev This error may occur if Xcode does not have the iOS SDK installed. Verify installed SDKs via the specified path. If not installed, click 'get' to install. ```bash # Check installed SDKs at: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/ ``` -------------------------------- ### Cache Configuration Example Source: https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloudrun/src/guide/resource/manage Demonstrates cache configuration priorities for static resources. When multiple cache rules apply, the last matching rule takes effect. This example shows how different file types and specific files are cached. ```text 目标 | 缓存时长 ---|--- 所有文件 | 2分钟 .php .jsp .aspx | 0秒 .jpg .png .gif | 300秒 /test/*.jpg | 400秒 /test/abc.jpg | 200秒 ``` -------------------------------- ### Cloud Function Call Example Source: https://developers.weixin.qq.com/miniprogram/dev/server/API/data-analysis/others/api_getvisitdistribution Example of calling the Get Visit Distribution API within a WeChat Cloud Function. ```javascript const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV, }) exports.main = async (event, context) => { try { const result = await cloud.openapi.analysis.getVisitDistribution({ "beginDate": '20170313', "endDate": '20170313' }) return result } catch (err) { return err } } ```