-
Notifications
You must be signed in to change notification settings - Fork 0
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
12 changed files
with
377 additions
and
2 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,2 @@ | ||
# Server listen port and IP address (:8080, 0.0.0.0:8080, 127.0.0.1:8080) | ||
SERVER_ADDR=:8080 |
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,21 @@ | ||
# Binaries for programs and plugins | ||
TencentCloudEIDMiddleware | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.db | ||
*.bin | ||
/release/ | ||
|
||
# Version control | ||
version.lock | ||
|
||
# Developement env | ||
.idea/* | ||
temp | ||
.env | ||
|
||
# Dist dir | ||
dist/ |
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,60 @@ | ||
env: | ||
- CI=false | ||
- GENERATE_SOURCEMAP=false | ||
before: | ||
hooks: | ||
- go mod tidy | ||
builds: | ||
- | ||
env: | ||
- CGO_ENABLED=0 | ||
|
||
binary: TencentCloudEIDMiddleware | ||
|
||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
goarch: | ||
- amd64 | ||
- arm | ||
- arm64 | ||
|
||
goarm: | ||
- 5 | ||
- 6 | ||
- 7 | ||
|
||
ignore: | ||
- goos: windows | ||
goarm: 5 | ||
- goos: windows | ||
goarm: 6 | ||
- goos: windows | ||
goarm: 7 | ||
|
||
archives: | ||
- format: tar.gz | ||
name_template: >- | ||
TencentCloudEIDMiddleware_{{.Tag}}_{{- .Os }}_{{ .Arch }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
release: | ||
draft: true | ||
prerelease: auto | ||
target_commitish: '{{ .Commit }}' | ||
name_template: "{{.Version}}" |
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,49 @@ | ||
# 腾讯云 “E证通” 中间件 | ||
当前版本:`v1.0.1` 作者:Prk | ||
|
||
腾讯云官网给的代码示例中,仅有 Go 和 Java 两种语言的。对于 Node.js 或 PHP 等语言来说,想要使用相同的方法较为复杂。 | ||
|
||
比如使用 PHP,就要引入比如 GMSSL 和 PHPKMS 的类库(因为它们支持 SM2、SM4 两种国密算法)。这显然是一件麻烦的事情,我还是打算使用 Go 语言做一个中间件。 | ||
|
||
如果你也觉得中间件方便那就一起用吧! | ||
|
||
|
||
## 如何使用 | ||
|
||
其实很简单,只需要使用 `GET` 方法请求传 Query 参数即可! | ||
|
||
```url | ||
/?key=xxx&des_key=xxx&user_info=xxx | ||
``` | ||
|
||
其中:`key` 为十六进制的私钥证书。`des_key` 和 `user_info` 为接口传回内容(详情请参考“[腾讯云官方文档](https://cloud.tencent.com/document/api/1007/54090)”)。 | ||
|
||
|
||
## 值得注意的是 | ||
|
||
如果你是 PHP,然后你的私钥文件 `CAkey.pem` 是下面的格式: | ||
|
||
```pem | ||
-----BEGIN EC PARAMETERS----- | ||
xxx | ||
-----END EC PARAMETERS----- | ||
-----BEGIN EC PRIVATE KEY----- | ||
xxxxxxx | ||
-----END EC PRIVATE KEY----- | ||
``` | ||
|
||
那么很正常。你可以使用下面的函式来获取十六进制做 Key 传。 | ||
|
||
```php | ||
function getCAKeyPEMHex(string $pem): string { | ||
return bin2hex( | ||
openssl_pkey_get_details( | ||
openssl_pkey_get_private( | ||
$pem | ||
) | ||
)['ec']['d'] | ||
); | ||
} | ||
``` | ||
|
||
在你请求本优雅的中间件的时候,别忘记使用 `urlencode()` 函式,避免腾讯传回的字符串的 `+` 被识别成空格 ` ` 等问题的产生。 |
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 +1,12 @@ | ||
package bootstrap | ||
|
||
import "fmt" | ||
|
||
func InitApplication() { | ||
fmt.Print(` | ||
Tencent Cloud EID Middleware | ||
V1.0.1, Author: Prk | ||
github.com/BiliPrk/TencentCloudEIDMiddleware | ||
============================================ | ||
`) | ||
} |
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 +1,5 @@ | ||
package bootstrap | ||
|
||
func Init() { | ||
InitApplication() | ||
} |
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,3 +1,33 @@ | ||
module TencentCloudEIDMiddleware | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.9.2 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/gin-gonic/gin v1.9.1 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.14.1 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/joho/godotenv v1.5.1 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | ||
github.com/tjfoc/gmsm v1.4.1 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
golang.org/x/arch v0.4.0 // indirect | ||
golang.org/x/crypto v0.11.0 // indirect | ||
golang.org/x/net v0.12.0 // indirect | ||
golang.org/x/sys v0.10.0 // indirect | ||
golang.org/x/text v0.11.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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 +1,31 @@ | ||
package TencentCloudEIDMiddleware | ||
package main | ||
|
||
import ( | ||
"TencentCloudEIDMiddleware/bootstrap" | ||
"TencentCloudEIDMiddleware/routers" | ||
"github.com/joho/godotenv" | ||
"log" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func init() { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatal("Error loading .env file") | ||
} | ||
|
||
bootstrap.Init() | ||
} | ||
|
||
func main() { | ||
api := routers.InitRouter() | ||
server := &http.Server{ | ||
Handler: api, | ||
} | ||
|
||
server.Addr = os.Getenv("SERVER_ADDR") | ||
if err := server.ListenAndServe(); err != nil { | ||
log.Fatalf("Failed to listen to %q: %s", os.Getenv("SERVER_ADDR"), err) | ||
} | ||
} |
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 +1,13 @@ | ||
package models | ||
package model | ||
|
||
type EidData struct { | ||
Name string `json:"name"` | ||
Type string `json:"idtype"` | ||
Number string `json:"idnum"` | ||
} | ||
|
||
type ResJSON struct { | ||
Code int `json:"code"` | ||
Message string `json:"msg"` | ||
Data *EidData `json:"data,omitempty"` | ||
} |
Oops, something went wrong.