76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package alicloud
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
// ExampleUsage 使用示例
|
|
func ExampleUsage() {
|
|
// 创建阿里云服务实例
|
|
// 请替换为您的实际配置
|
|
host := "https://kzidcardv1.market.alicloudapi.com"
|
|
appCode := "您的AppCode"
|
|
|
|
service := NewAlicloudService(host, appCode)
|
|
|
|
// 示例:验证身份证信息
|
|
name := "张三"
|
|
idCard := "110101199001011234"
|
|
|
|
// 构建请求参数
|
|
params := map[string]interface{}{
|
|
"name": name,
|
|
"idcard": idCard,
|
|
}
|
|
|
|
// 调用API
|
|
responseBody, err := service.CallAPI("api-mall/api/id_card/check", params)
|
|
if err != nil {
|
|
log.Printf("验证失败: %v", err)
|
|
return
|
|
}
|
|
|
|
// 解析完整响应结构
|
|
var response struct {
|
|
Msg string `json:"msg"`
|
|
Success bool `json:"success"`
|
|
Code int `json:"code"`
|
|
Data struct {
|
|
Birthday string `json:"birthday"`
|
|
Result int `json:"result"`
|
|
Address string `json:"address"`
|
|
OrderNo string `json:"orderNo"`
|
|
Sex string `json:"sex"`
|
|
Desc string `json:"desc"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
if err := json.Unmarshal(responseBody, &response); err != nil {
|
|
log.Printf("响应解析失败: %v", err)
|
|
return
|
|
}
|
|
|
|
// 检查响应状态
|
|
if response.Code != 200 {
|
|
log.Printf("API返回错误: code=%d, msg=%s", response.Code, response.Msg)
|
|
return
|
|
}
|
|
|
|
idCardData := response.Data
|
|
|
|
fmt.Printf("验证结果: %d\n", idCardData.Result)
|
|
fmt.Printf("描述: %s\n", idCardData.Desc)
|
|
fmt.Printf("生日: %s\n", idCardData.Birthday)
|
|
fmt.Printf("性别: %s\n", idCardData.Sex)
|
|
fmt.Printf("地址: %s\n", idCardData.Address)
|
|
fmt.Printf("订单号: %s\n", idCardData.OrderNo)
|
|
|
|
// 判断验证结果
|
|
if idCardData.Result == 1 {
|
|
fmt.Println("身份证信息验证通过")
|
|
} else {
|
|
fmt.Println("身份证信息验证失败")
|
|
}
|
|
} |