A comprehensive WeChat public account server implemented in Go, providing various features such as todo management, scheduled notifications, and media backup with external network access via ngrok.
- Service deployed on a home network small server (including Golang program, MySQL, etc.)
- External network access provided through ngrok proxy for WeChat public account, uni-app, etc.
- Message notifications pushed to WeChat via email sending
- Cross-compile to generate arm64 Linux binary package on development machine
- Transfer via SCP to small server
- Send signal to restart service
- Using花生壳 (Phddns) software to provide mapping services
- Map MySQL to allow development machine to start service normally
- Map small server SSH port to allow normal login and file transfer
vi ~/.weixin_app/config/config.yml- General configuration (MySQL database configuration)
database:
username: user
password: pass
host: 192.168.33.174
port: 3306
dbname: weixin_app
timeout: 10svi ~/.weixin_app/config/private_config.yml- Private configuration
encrypt: # For encrypting/decrypting sensitive information
key: 123456... # (16 characters)
weixin: # WeChat Open Platform configuration
appid: xxxx # Fill in after AES encryption using encrypt.key
appSecret: xxxx # Fill in after AES encryption using encrypt.key
token: xxxx # Fill in after AES encryption using encrypt.key
mail: # For sending notifications
address: fffff # Fill in after AES encryption using encrypt.key
pass: fff # Fill in after AES encryption using encrypt.key (email password or authorization code)
name: Labali # Sender user name
smtpHost: smtp.qq.com
receiverList: [ # Find corresponding email by WeChat openid for sending email notifications
openId: "xxx", # (WeChat public account openid)
address: "[email protected]"
,{
openId: "ddd",
address: "[email protected]"
}
]
admin:
accounts: [ # Administrator WeChat public account openid
"oqV-xxxxx",
"oqV-xxxxx"
] go run cmd/main.go- Access http://127.0.0.1:8989/ to check if startup was successful
- Use ngrok to configure proxy for external network access
- Go to WeChat public account backend, configure development callback link
- Settings & Development -> Basic Configuration -> Server Configuration -> Server Address(URL) https://xxxx.ngrok.io/labali_msg
- Add, view, delete todo items
- Scheduled WeChat message reminders (implemented via email sending, WeChat needs to have email reminders enabled)
- Save sent images or videos to server, and summarize and send email backup the next day
- Connect with WeChat Open Platform, receive passive messages, process and reply
- Query and cache WeChat public account access token for scenarios where active requests are sent to WeChat public account server
- Send email notifications to eligible WeChat accounts
- Sensitive configurations use AES encryption/decryption
- Receive WeChat image or video links, download to corresponding local server location
- Server external IP periodic check, send email notification if changed (querying WeChat public account accessToken requires configuring whitelist IP)
- Settings & Development -> Basic Configuration -> Public Account Development Information -> IP Whitelist
- This feature is not fully implemented
- Service graceful restart on signal reception
- Send email notification when service starts successfully, with service information (external proxy address, external IP, internal IP, etc.)
- Check if ngrok process is running when service starts, trigger start if not
- Service deployment and update scripts
./script/make.sh- Package binary files./script/upload.sh- Upload to server./script/deploy.sh- Restart service
- Periodic check of server internal IP, send email notification if changed, for external network connection via Peanut Shell for SSH to home server
- Server restart, configure automatic service startup (centos startup item configuration)
- weixin/wxaction/wxaction.go
registerHandler(cmd, func(openid, content string) string {
return "msg"
}) - Examples of using gorm
- How to connect with WeChat public account and receive passive messages
- How to actively query information through WeChat public account API
- Usage of scheduled task github.com/robfig/cron/v3
- Using github.com/fvbock/endless for graceful service restart
- Examples of using gopkg.in/yaml.v2 for reading YAML configuration files
- Store user openid and corresponding email in database, currently configured in private_config.yml#mail.receiverList
- Store administrator openid in database, currently configured in private_config.yml#admin.accounts
- Make scheduled email reminder times configurable, cron/cron.go
- Auto-start, start Peanut Shell and send QR code to email, scan to SSH to server from external network
- Auto-deployment script on merging to master, git hook triggers service update and restart
- Add user, block user, send message notifications to administrator account id
- Command context memory capability
- Integrate configuration center, such as nacos
- Saved images, support generating geolocation city time watermark based on image information
- Current code implementation only considers single-server service
- If using sqlite, consider periodic backup to git, common/backup/backup.go
This project is licensed under the terms of the LICENSE file.
For more information, visit deepwiki