UniApp WeChat mini program demo
sdk/uniapp/demo-miniprogram in the repository is a WeChat mini program example based on @deeprespond/im-uniapp/miniprogram; the same code also compiles to H5 for debugging in the browser. Its pages follow WeChat's layout: "Messages", "Contacts" and "Me" tabs, plus second-level pages such as chats, group chats, friend profiles and friend requests. Use it to try the mini program SDK's features, or move its store and page state handling into your own UniApp project.
What it covers
| Area | Covers |
|---|---|
| Account | Password sign-in and sign-up, automatic sign-in restore, temporarily changing the server address, logs |
| Conversations | Unread badges, pinning, marking unread, drafts, typing indicators, search, clearing history, unread badge on the tabBar |
| Messages | Text, emoji, images, video, files, voice, location; recall, reactions, forwarding, resending; automatic read marking |
| Friends | Sending, accepting and declining friend requests, remarks, blocklist, removing; contact search |
| Group chat | Starting group chats, inviting and removing members, renaming, leaving, dissolving, system notices in the group |
| Profile | Editing the nickname and avatar, friend profile pages |
| Audio and video | The one-to-one call entry only appears in H5; the mini program SDK doesn't support call or channel media yet, and the UI says so |
Run it
cd sdk/uniapp/demo-miniprogram
cp .env.example .env.local
# 编辑 .env.local;不要提交真实密码、Ticket 或长期密钥。
pnpm installThere are two ways to run it:
| Mode | Command | Description |
|---|---|---|
| H5 in the browser | pnpm dev:h5 | Open http://127.0.0.1:5176 to debug page logic and SDK calls in the browser. The Vite proxy forwards /client (including WebSocket) to the IM service, and /im-private and /im-public to S3-compatible storage |
| WeChat Developer Tools | pnpm dev:mp-weixin | Output goes to dist/dev/mp-weixin; import that directory in WeChat Developer Tools. Build for release with pnpm build:mp-weixin |
While debugging in WeChat Developer Tools you can turn off domain verification; on real devices, configure the API, socket and file download domains in the mini program admin console. WeChat base library 2.21.3 or later is required.
Environment variables
Copy .env.example to .env.local and fill in what you need:
| Variable | Description |
|---|---|
VITE_IM_APP_KEY | The app's App Key; default org#app |
VITE_IM_API_URL | IM service address; for H5 debugging, the local service is enough (forwarded by the dev proxy) |
VITE_IM_WS_URL | WebSocket address, optional |
Platform notes
- Recording, location and opening files come from the mini program's
wx.*APIs; in H5, when the browser lacks the permission, the UI shows the SDK's failure reason. - Mini programs don't support call or channel media yet (
channels.supportedisfalse), and the UI says so; the one-to-one call entry only appears in H5. - Your server issues sign-in tickets; never put the AppSecret in the mini program.
Testing and source package
Page logic and SDK calls were tested with three accounts through Playwright on the H5 target; the native wx.* features in WeChat Developer Tools and on real devices need separate testing in an environment with a graphical interface.
Demo source package (1.0.1, without dependencies or local config): deeprespond-uniapp-demo-miniprogram-1.0.1.zip
For installing and downloading the SDK used in mini programs, see the mini program SDK.
