mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
added GetPhoneNumberWithContext (#812)
Signed-off-by: mqf20 <mingqingfoo@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package business
|
package business
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
"github.com/silenceper/wechat/v2/util"
|
||||||
@@ -28,13 +29,18 @@ type PhoneInfo struct {
|
|||||||
|
|
||||||
// GetPhoneNumber code换取用户手机号。 每个code只能使用一次,code的有效期为5min
|
// GetPhoneNumber code换取用户手机号。 每个code只能使用一次,code的有效期为5min
|
||||||
func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneInfo, err error) {
|
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()
|
accessToken, err := business.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf(getPhoneNumberURL, accessToken)
|
uri := fmt.Sprintf(getPhoneNumberURL, accessToken)
|
||||||
response, err := util.PostJSON(uri, in)
|
response, err := util.PostJSONContext(ctx, uri, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user