-
Notifications
You must be signed in to change notification settings - Fork 281
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
Showing
5 changed files
with
139 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
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,20 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
// 用户信息 | ||
type Auth struct { | ||
request *request.Request | ||
// 组成完整的 URL 地址 | ||
// 默认包含 AccessToken | ||
conbineURI func(url string, req interface{}) (string, error) | ||
} | ||
|
||
func NewAuth(request *request.Request, conbineURI func(url string, req interface{}) (string, error)) *Auth { | ||
sm := Auth{ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiCheckEncryptedData = "/wxa/business/checkencryptedmsg" | ||
|
||
type CheckEncryptedDataRequest struct { | ||
// 必填 加密数据的sha256,通过Hex(Base16)编码后的字符串 | ||
EncryptedMsgHash string `json:"encrypted_msg_hash"` | ||
} | ||
|
||
type CheckEncryptedDataResponse struct { | ||
request.CommonError | ||
// 是否是合法的数据 | ||
Valid bool `json:"vaild"` | ||
// 加密数据生成的时间戳 | ||
CreateTime int64 `json:"create_time"` | ||
} | ||
|
||
// 检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据 | ||
func (cli *Auth) CheckEncryptedData(req *CheckEncryptedDataRequest) (*CheckEncryptedDataResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiCheckEncryptedData, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(CheckEncryptedDataResponse) | ||
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,39 @@ | ||
package auth | ||
|
||
import "github.com/medivhzhan/weapp/v3/request" | ||
|
||
const apiGetPaidUnionId = "/wxa/getpaidunionid" | ||
|
||
type GetPaidUnionIdRequest struct { | ||
// 必填 支付用户唯一标识 | ||
Openid string `json:"openid"` | ||
// 非必填 微信支付订单号 | ||
TransactionId string `json:"transaction_id"` | ||
// 非必填 微信支付分配的商户号,和商户订单号配合使用 | ||
MchId string `json:"mch_id"` | ||
// 非必填 微信支付商户订单号,和商户号配合使用 | ||
OutTradeNo string `json:"out_trade_no"` | ||
} | ||
|
||
type GetPaidUnionIdResponse struct { | ||
request.CommonError | ||
// 用户唯一标识,调用成功后返回 | ||
UnionID string `json:"unionid"` | ||
} | ||
|
||
// 用户支付完成后,获取该用户的 UnionId,无需用户授权。 | ||
func (cli *Auth) GetPaidUnionId(req *GetPaidUnionIdRequest) (*GetPaidUnionIdResponse, error) { | ||
|
||
api, err := cli.conbineURI(apiGetPaidUnionId, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetPaidUnionIdResponse) | ||
err = cli.request.Get(api, 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