forked from silenceper/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ea817a
commit 96678d2
Showing
12 changed files
with
831 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ _testmain.go | |
.vscode/ | ||
vendor/*/ | ||
.idea/ | ||
examples/tcb/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 小程序-云开发 SDK | ||
|
||
Tencent Cloud Base [文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/) | ||
|
||
## 使用说明 | ||
|
||
**初始化配置** | ||
|
||
```golang | ||
//使用memcache保存access_token,也可选择redis或自定义cache | ||
memCache=cache.NewMemcache("127.0.0.1:11211") | ||
|
||
//配置小程序参数 | ||
config := &wechat.Config{ | ||
AppID: "your app id", | ||
AppSecret: "your app secret", | ||
Cache: memCache, | ||
} | ||
wc := wechat.NewWechat(config) | ||
wcTcb := wc.GetTcb() | ||
``` | ||
|
||
### 举例 | ||
#### 触发云函数 | ||
```golang | ||
res, err := wcTcb.UploadFile("test-6ku2s", "golang.png") | ||
if err != nil { | ||
panic(err) | ||
} | ||
``` | ||
|
||
更多使用方法参考[GODOC](https://godoc.org/github.com/silenceper/wechat/tcb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tcb | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/silenceper/wechat/util" | ||
) | ||
|
||
const ( | ||
//触发云函数 | ||
invokeCloudFunctionURL = "https://api.weixin.qq.com/tcb/invokecloudfunction" | ||
) | ||
|
||
//InvokeCloudFunctionRes 云函数调用返回结果 | ||
type InvokeCloudFunctionRes struct { | ||
util.CommonError | ||
RespData string `json:"resp_data"` //云函数返回的buffer | ||
} | ||
|
||
//InvokeCloudFunction 云函数调用 | ||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html | ||
func (tcb *Tcb) InvokeCloudFunction(env, name, args string) (*InvokeCloudFunctionRes, error) { | ||
accessToken, err := tcb.GetAccessToken() | ||
if err != nil { | ||
return nil, err | ||
} | ||
uri := fmt.Sprintf("%s?access_token=%s&env=%s&name=%s", invokeCloudFunctionURL, accessToken, env, name) | ||
response, err := util.HTTPPost(uri, args) | ||
if err != nil { | ||
return nil, err | ||
} | ||
invokeCloudFunctionRes := &InvokeCloudFunctionRes{} | ||
err = util.DecodeWithError(response, invokeCloudFunctionRes, "InvokeCloudFunction") | ||
return invokeCloudFunctionRes, err | ||
} |
Oops, something went wrong.