12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package analysis
- import (
- "gadm-ods/apis"
- "gadm-ods/common.in/clinit"
- "gadm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // DY身份认证()
- func ParasOds1(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- if len(requestParams) == 0 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- idCard := gjson.Get(requestParams,"id_card").String()
- name := gjson.Get(requestParams,"name").String()
- fmt.Println(idCard,name)
- if idCard == "" || name == "" {
- return nil, fmt.Errorf("数据异常,身份证姓名任意为空")
- }
- responseParams := data.Get("response_params").String()
- errorCode := gjson.Get(responseParams, "code").String()
- if errorCode != "0" {
- return nil, fmt.Errorf("数据异常,没有数据", errorCode)
- }
- compStatus := gjson.Get(responseParams, "data.compStatus").String()
- if compStatus != "1" {
- return nil, fmt.Errorf("数据异常,不匹配")
- }
- dataMap := make(map[string]string)
- dataMap["id_card"] = idCard
- dataMap["name"] = name
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds1(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds1(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods1 := &model.Ods1{}
- ods1.Name = dataMapList[0]["name"]
- ods1.IdCard = dataMapList[0]["id_card"]
- ods1.Content = msg.Content
- err = ods1.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- }
- return nil, nil
- }
- return dataMapList, nil
- }
|