Skip to content

Commit 5dc05df

Browse files
author
lilang
committed
Merge branch 'dev_qr' into 'master' (merge request !85)
添加方法
2 parents 1025874 + 8b6c807 commit 5dc05df

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

ci.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,37 @@ func (s *CIService) GetQRcode(ctx context.Context, name string, cover int, opt *
12651265
return &res, resp, err
12661266
}
12671267

1268+
type GetQRcodeResultV2 struct {
1269+
XMLName xml.Name `xml:"Response"`
1270+
CodeStatus int `xml:"CodeStatus,omitempty"`
1271+
QRcodeInfo []QRcodeInfo `xml:"QRcodeInfo,omitempty"`
1272+
ResultImage string `xml:"ResultImage,omitempty"`
1273+
}
1274+
1275+
// 二维码识别-下载时识别 https://cloud.tencent.com/document/product/436/54070
1276+
func (s *CIService) GetQRcodeV2(ctx context.Context, name string, cover int, opt *ObjectGetOptions, id ...string) (*GetQRcodeResultV2, *Response, error) {
1277+
var u string
1278+
if len(id) == 1 {
1279+
u = fmt.Sprintf("/%s?versionId=%s&ci-process=QRcode&cover=%v", encodeURIComponent(name), id[0], cover)
1280+
} else if len(id) == 0 {
1281+
u = fmt.Sprintf("/%s?ci-process=QRcode&cover=%v", encodeURIComponent(name), cover)
1282+
} else {
1283+
return nil, nil, errors.New("wrong params")
1284+
}
1285+
1286+
var res GetQRcodeResultV2
1287+
sendOpt := sendOptions{
1288+
baseURL: s.client.BaseURL.BucketURL,
1289+
uri: u,
1290+
method: http.MethodGet,
1291+
optQuery: opt,
1292+
optHeader: opt,
1293+
result: &res,
1294+
}
1295+
resp, err := s.client.send(ctx, &sendOpt)
1296+
return &res, resp, err
1297+
}
1298+
12681299
type GenerateQRcodeOptions struct {
12691300
QRcodeContent string `url:"qrcode-content,omitempty"`
12701301
Mode int `url:"mode,omitempty"`

ci_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,61 @@ func TestCIService_GetQRcode(t *testing.T) {
874874
}
875875
}
876876

877+
func TestCIService_GetQRcodeV2(t *testing.T) {
878+
{
879+
setup()
880+
mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
881+
testMethod(t, r, http.MethodGet)
882+
vs := values{
883+
"ci-process": "QRcode",
884+
"cover": "1",
885+
}
886+
testFormValues(t, r, vs)
887+
})
888+
889+
_, _, err := client.CI.GetQRcodeV2(context.Background(), "test.jpg", 1, nil)
890+
if err != nil {
891+
t.Fatalf("CI.GetQRcodeV2 returned error: %v", err)
892+
}
893+
teardown()
894+
}
895+
896+
{
897+
setup()
898+
mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
899+
testMethod(t, r, http.MethodGet)
900+
vs := values{
901+
"ci-process": "QRcode",
902+
"cover": "1",
903+
"versionId": "1.1",
904+
}
905+
testFormValues(t, r, vs)
906+
})
907+
_, _, err := client.CI.GetQRcodeV2(context.Background(), "test.jpg", 1, nil, "1.1")
908+
if err != nil {
909+
t.Fatalf("CI.GetQRcodeV2 returned error: %v", err)
910+
}
911+
teardown()
912+
}
913+
914+
{
915+
setup()
916+
mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
917+
testMethod(t, r, http.MethodGet)
918+
vs := values{
919+
"ci-process": "QRcode",
920+
"cover": "1",
921+
}
922+
testFormValues(t, r, vs)
923+
})
924+
_, _, err := client.CI.GetQRcodeV2(context.Background(), "test.jpg", 1, nil, "1.1", "1.2")
925+
if err == nil || err.Error() != "wrong params" {
926+
t.Fatalf("CI.GetQRcodeV2 returned error: %v", err)
927+
}
928+
teardown()
929+
}
930+
}
931+
877932
func TestCIService_GenerateQRcode(t *testing.T) {
878933
setup()
879934
defer teardown()

example/CI/ai_recognition/qrcode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func qRcodeRecognitionWhenDownload() {
9191
})
9292

9393
name := "pic/qrcode.jpg"
94-
res, _, err := c.CI.GetQRcode(context.Background(), name, 1, nil)
94+
res, _, err := c.CI.GetQRcodeV2(context.Background(), name, 1, nil)
9595
log_status(err)
9696
fmt.Printf("%+v\n", res)
9797
}

0 commit comments

Comments
 (0)