From d0abd7a02ae2e1b7bbfd40d0bd6931a3c0840635 Mon Sep 17 00:00:00 2001 From: mqf20 Date: Tue, 7 Jan 2025 13:19:21 +0800 Subject: [PATCH] added GetPhoneNumberWithContext Signed-off-by: mqf20 --- miniprogram/business/phone_number.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/miniprogram/business/phone_number.go b/miniprogram/business/phone_number.go index 72921499..38592cce 100644 --- a/miniprogram/business/phone_number.go +++ b/miniprogram/business/phone_number.go @@ -1,6 +1,7 @@ package business import ( + "context" "fmt" "github.com/silenceper/wechat/v2/util" @@ -28,13 +29,18 @@ type PhoneInfo struct { // GetPhoneNumber code换取用户手机号。 每个code只能使用一次,code的有效期为5min func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneInfo, err error) { + return business.GetPhoneNumberWithContext(context.Background(), in) +} + +// GetPhoneNumberWithContext 利用context将code换取用户手机号。 每个code只能使用一次,code的有效期为5min +func (business *Business) GetPhoneNumberWithContext(ctx context.Context, in *GetPhoneNumberRequest) (info PhoneInfo, err error) { accessToken, err := business.GetAccessToken() if err != nil { return } uri := fmt.Sprintf(getPhoneNumberURL, accessToken) - response, err := util.PostJSON(uri, in) + response, err := util.PostJSONContext(ctx, uri, in) if err != nil { return }