Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat-client-sdk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
go
wechat-client-sdk
Commits
6bb13dfc
Commit
6bb13dfc
authored
Oct 16, 2022
by
yemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
032776f0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
25 deletions
+30
-25
HttpUtil.go
httpclient/HttpUtil.go
+4
-9
main.go
main.go
+0
-5
Auth.go
minipro/Auth.go
+5
-5
Client.go
minipro/Client.go
+14
-0
PhoneNumber.go
minipro/PhoneNumber.go
+2
-2
client_test.go
test/client_test.go
+5
-4
No files found.
httpclient/HttpUtil.go
View file @
6bb13dfc
...
...
@@ -8,16 +8,11 @@ import (
)
// HttpClient 本项目中使用的http客户端
var
HttpClient
*
http
.
Client
func
init
()
{
HttpClient
=
&
http
.
Client
{}
//HttpClient.Timeout = config.Conf.Http.Client.Timeout * time.Millisecond //设置请求超时时间
}
var
httpClient
*
http
.
Client
=
&
http
.
Client
{}
// Get get方法的http请求,返回原始字符串
func
Get
(
url
string
)
([]
byte
,
error
)
{
rep
,
err
:=
H
ttpClient
.
Get
(
url
)
rep
,
err
:=
h
ttpClient
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -43,7 +38,7 @@ func GetWithHeader(url string, header *map[string]string) ([]byte, error) {
}
}
//发送请求
rep
,
err
:=
H
ttpClient
.
Do
(
req
)
rep
,
err
:=
h
ttpClient
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -84,7 +79,7 @@ func Post(url string, header *map[string]string, bodyParam interface{}) ([]byte,
}
}
//发送请求
rep
,
err
:=
H
ttpClient
.
Do
(
req
)
rep
,
err
:=
h
ttpClient
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
main.go
deleted
100644 → 0
View file @
032776f0
package
main
func
main
()
{
}
sma
pro/Auth.go
→
mini
pro/Auth.go
View file @
6bb13dfc
package
sma
pro
package
mini
pro
import
(
"encoding/json"
...
...
@@ -9,9 +9,9 @@ import (
// NewAccessToken 获取接口调用凭据。
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html
func
NewAccessToken
(
appId
string
,
secret
string
)
(
*
AccessTokenResponse
,
error
)
{
func
(
c
*
MiniClient
)
NewAccessToken
(
)
(
*
AccessTokenResponse
,
error
)
{
result
:=
&
AccessTokenResponse
{}
var
url
=
fmt
.
Sprintf
(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
,
appId
,
secret
)
var
url
=
fmt
.
Sprintf
(
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
,
c
.
appId
,
c
.
secret
)
r
,
err
:=
httpclient
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -25,9 +25,9 @@ func NewAccessToken(appId string, secret string) (*AccessTokenResponse,error) {
// Code2Session 登录凭证校验。
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
func
Code2Session
(
code
string
,
appId
string
,
secret
string
)
(
*
Code2SessionResponse
,
error
)
{
func
(
c
*
MiniClient
)
Code2Session
(
code
string
)
(
*
Code2SessionResponse
,
error
)
{
result
:=
&
Code2SessionResponse
{}
var
url
=
fmt
.
Sprintf
(
"https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"
,
appId
,
secret
,
code
)
var
url
=
fmt
.
Sprintf
(
"https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"
,
c
.
appId
,
c
.
secret
,
code
)
r
,
err
:=
httpclient
.
Get
(
url
)
if
err
!=
nil
{
return
nil
,
err
...
...
minipro/Client.go
0 → 100644
View file @
6bb13dfc
package
minipro
type
MiniClient
struct
{
appId
string
secret
string
}
// NewMiniClient 返回MiniClient
func
NewMiniClient
(
appId
string
,
secret
string
)
*
MiniClient
{
c
:=
MiniClient
{
appId
,
secret
}
return
&
c
}
\ No newline at end of file
sma
pro/PhoneNumber.go
→
mini
pro/PhoneNumber.go
View file @
6bb13dfc
package
sma
pro
package
mini
pro
import
(
"encoding/json"
...
...
@@ -9,7 +9,7 @@ import (
// GetUserPhoneNumber 换取用户手机号
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
func
GetUserPhoneNumber
(
code
string
,
accessToken
string
)
(
*
PhoneNumberResponse
,
error
)
{
func
(
c
*
MiniClient
)
GetUserPhoneNumber
(
code
string
,
accessToken
string
)
(
*
PhoneNumberResponse
,
error
)
{
result
:=
&
PhoneNumberResponse
{}
url
:=
fmt
.
Sprintf
(
"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
,
accessToken
)
bodyParam
:=
phoneNumberParam
{
code
}
...
...
test/client_test.go
View file @
6bb13dfc
...
...
@@ -2,26 +2,26 @@ package test
import
(
"fmt"
"git.168cad.top/go/wechat-client-sdk/
sma
pro"
"git.168cad.top/go/wechat-client-sdk/
mini
pro"
"log"
"testing"
)
func
TestCode2Session
(
t
*
testing
.
T
)
{
r
,
err
:=
sma
pro
.
Code2Session
(
"033DEr0w36huoZ2Ga22w3wXeTR1DEr0g"
,
""
,
""
)
r
,
err
:=
mini
pro
.
Code2Session
(
"033DEr0w36huoZ2Ga22w3wXeTR1DEr0g"
,
""
,
""
)
log
.
Println
(
err
)
log
.
Println
(
fmt
.
Sprintf
(
"%+v
\n
"
,
*
r
))
}
func
TestNewAccessToken
(
t
*
testing
.
T
)
{
r
,
err
:=
sma
pro
.
NewAccessToken
(
""
,
""
)
r
,
err
:=
mini
pro
.
NewAccessToken
(
""
,
""
)
log
.
Println
(
err
)
log
.
Println
(
fmt
.
Sprintf
(
"%+v
\n
"
,
*
r
))
}
func
TestGetUserPhoneNumber
(
t
*
testing
.
T
)
{
accessToken
:=
"61_uqRWPGxxveyZnFoqCsddx9uY5w6uTZtHckodV8sS80OKtEBKJHM1udwD8ImlOa8UXnO_o3A4Qi3cwNtBvoC_fXSFnmXzJaD1cw-dMwaRGoz7XxTLhxvAeA_Bou4TWqPAmXnmmTknNwe9mU3_PVPiAGAZFZ"
r
,
err
:=
sma
pro
.
GetUserPhoneNumber
(
"fa46d5412a1c7053de2f930a043fa92b4d253eb83ce4e23d0fe0304bef65ded1"
,
accessToken
)
r
,
err
:=
mini
pro
.
GetUserPhoneNumber
(
"fa46d5412a1c7053de2f930a043fa92b4d253eb83ce4e23d0fe0304bef65ded1"
,
accessToken
)
log
.
Println
(
err
)
log
.
Println
(
fmt
.
Sprintf
(
"%+v
\n
"
,
*
r
))
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment