-
Notifications
You must be signed in to change notification settings - Fork 282
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
c793df4
commit 999adeb
Showing
3 changed files
with
64 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package phonenumber | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGetPhoneNumber = "/wxa/business/getuserphonenumber" | ||
|
||
type GetPhoneNumberRequest struct { | ||
Code string `json:"code"` | ||
} | ||
|
||
type GetPhoneNumberResponse struct { | ||
request.CommonError | ||
Data []struct { | ||
PhoneNumber string `json:"phoneNumber"` // 用户绑定的手机号(国外手机号会有区号) | ||
PurePhoneNumber string `json:"purePhoneNumber"` // 没有区号的手机号 | ||
CountryCode string `json:"countryCode"` // 区号 | ||
Watermark []struct { | ||
Appid string `json:"appid"` // 小程序appid | ||
Timestamp int64 `json:"timestamp"` // 用户获取手机号操作的时间戳 | ||
} `json:"watermark"` // 数据水印 | ||
} `json:"phone_info"` // 类目列表 | ||
} | ||
|
||
// code换取用户手机号。 每个code只能使用一次,code的有效期为5min | ||
func (cli *Phonenumber) GetPhoneNumber(req *GetPhoneNumberRequest) (*GetPhoneNumberResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGetPhoneNumber, nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetPhoneNumberResponse) | ||
err = cli.request.Post(api, req, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
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,19 @@ | ||
package phonenumber | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
type Phonenumber struct { | ||
request *request.Request | ||
// 组成完整的 URL 地址 | ||
// 默认包含 AccessToken | ||
conbineURI func(url string, req interface{}, withToken bool) (string, error) | ||
} | ||
|
||
func NewPhonenumber(request *request.Request, conbineURI func(url string, req interface{}, withToken bool) (string, error)) *Phonenumber { | ||
sm := Phonenumber{ | ||
request: request, | ||
conbineURI: conbineURI, | ||
} | ||
|
||
return &sm | ||
} |
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