-
Notifications
You must be signed in to change notification settings - Fork 11
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
160 changed files
with
5,176 additions
and
2,005 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
go.sum | ||
go.work.sum | ||
example/basic/go.sum | ||
example/sub_app/go.sum | ||
.idea |
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,15 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${workspaceFolder}/examples/sub_app" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
### 基本接口调用 | ||
|
||
> 直接调用 应用管理 服务 | ||
> 示例包含 oauth 登录 跟 app 信息获取 | ||
> HTTP接口封装调用示例 |
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
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
lSysApi "lsysrest/lsysrest" | ||
"math/rand" | ||
"testing" | ||
) | ||
|
||
// oauth 登录示例 | ||
|
||
func getApi() *lSysApi.RestApi { | ||
return lSysApi.NewRestApi(&lSysApi.RestApiConfig{ | ||
//应用在 https://www.lsys.cc/app.html#/user/app 申请 | ||
AppId: "1212f", //应用ID | ||
AppSecret: "3f95638a1e07b87df2b64e09c2541dac", //应用Secret | ||
AppHost: "http://www.lsys.cc", //应用HOST | ||
AppOAuthSecret: "2a97bf1b4f075b0ca7467e7c6b223f89", //应用OauthSecret | ||
AppOAuthHost: "http://www.lsys.cc/oauth.html", | ||
}) | ||
} | ||
|
||
// 第一步 | ||
// 登录地址 | ||
func TestGetLoginUrl(t *testing.T) { | ||
api := getApi() | ||
b := make([]byte, 6) | ||
rand.Read(b) | ||
url := api.OAuthAuthorizationUrl(context.Background(), "http://127.0.0.1:8080/", "user_info,user_mobile", hex.EncodeToString(b)) | ||
fmt.Printf("url :%s \n", url) | ||
} | ||
|
||
// 第二步 | ||
// 登录后获取TOKEN | ||
func TestGetToken(t *testing.T) { | ||
api := getApi() | ||
er, token := api.OAuthAccessToken(context.Background(), "c936ed75412a0b8f") | ||
if er == nil { | ||
fmt.Printf("token :%s \n", token.AccessToken) | ||
} else { | ||
fmt.Printf("err :%s \n", er.Error()) | ||
return | ||
} | ||
} | ||
|
||
// //通过TOKEN得到用户信息 | ||
func TestGetUserData(t *testing.T) { | ||
api := getApi() | ||
tokenApi := api.TokenRestApi("58f34acd692b70e1") | ||
err, data := tokenApi.OAuthUserInfo(context.Background(), true, true, false, false, false, false) | ||
if err == nil { | ||
fmt.Printf("sub app output :%s", data) | ||
} else { | ||
fmt.Printf("error :%s", err.Error()) | ||
} | ||
} | ||
|
||
// //刷新TOKEN | ||
func TestRefreshToken(t *testing.T) { | ||
api := getApi() | ||
tokenApi := api.TokenRestApi("58f34acd692b70e1") | ||
er, token1 := tokenApi.OAuthRefreshToken(context.Background()) | ||
if er == nil { | ||
fmt.Printf("token :%s \n", token1.AccessToken) | ||
} else { | ||
fmt.Printf("err :%s \n", er.Error()) | ||
return | ||
} | ||
} |
Oops, something went wrong.