You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
package miniapp
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
|
|
"github.com/ArtisanCloud/PowerWeChat/v2/src/miniProgram"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func MiniProgramAppByEnv() (*miniProgram.MiniProgram, error) {
|
|
// 从env环境变量获取小程序配置
|
|
openid := os.Getenv("WECHAT_MINIAPP_OPENID")
|
|
secret := os.Getenv("WECHAT_MINIAPP_SECRET")
|
|
fmt.Println(openid, secret)
|
|
return MiniProgramApp(openid, secret, nil)
|
|
}
|
|
|
|
func MiniProgramApp(appid, secret string, cache kernel.CacheInterface) (*miniProgram.MiniProgram, error) {
|
|
miniProgramApp, err := miniProgram.NewMiniProgram(&miniProgram.UserConfig{
|
|
AppID: appid, // 小程序appid
|
|
Secret: secret, // 小程序app secret
|
|
HttpDebug: true,
|
|
Log: miniProgram.Log{
|
|
Level: "debug",
|
|
File: "./wechat.log",
|
|
},
|
|
// 可选,不传默认走程序内存
|
|
//Cache: kernel.NewRedisClient(&kernel.RedisOptions{
|
|
// Addr: "127.0.0.1:6379",
|
|
// Password: "",
|
|
// DB: 0,
|
|
//}),
|
|
Cache: cache,
|
|
})
|
|
|
|
if err != nil {
|
|
log.Printf("NewMiniProgram error: %v\n", err)
|
|
}
|
|
return miniProgramApp, err
|
|
|
|
}
|