Skip to content

Commit

Permalink
added GetPhoneNumberWithContext
Browse files Browse the repository at this point in the history
Signed-off-by: mqf20 <[email protected]>
  • Loading branch information
mqf20 committed Jan 7, 2025
1 parent 17521d0 commit d0abd7a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion miniprogram/business/phone_number.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package business

import (
"context"
"fmt"

"github.com/silenceper/wechat/v2/util"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d0abd7a

Please sign in to comment.