ods1.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package analysis
  4. import (
  5. "gadm-ods/apis"
  6. "gadm-ods/common.in/clinit"
  7. "gadm-ods/model"
  8. "fmt"
  9. "github.com/tidwall/gjson"
  10. "strings"
  11. )
  12. // DY身份认证()
  13. func ParasOds1(content string) (ret []map[string]string, err error) {
  14. data := gjson.Parse(content)
  15. requestParams := data.Get("request_params").String()
  16. if len(requestParams) == 0 {
  17. return nil, fmt.Errorf("数据异常,没有数据")
  18. }
  19. idCard := gjson.Get(requestParams,"id_card").String()
  20. name := gjson.Get(requestParams,"name").String()
  21. fmt.Println(idCard,name)
  22. if idCard == "" || name == "" {
  23. return nil, fmt.Errorf("数据异常,身份证姓名任意为空")
  24. }
  25. responseParams := data.Get("response_params").String()
  26. errorCode := gjson.Get(responseParams, "code").String()
  27. if errorCode != "0" {
  28. return nil, fmt.Errorf("数据异常,没有数据", errorCode)
  29. }
  30. compStatus := gjson.Get(responseParams, "data.compStatus").String()
  31. if compStatus != "1" {
  32. return nil, fmt.Errorf("数据异常,不匹配")
  33. }
  34. dataMap := make(map[string]string)
  35. dataMap["id_card"] = idCard
  36. dataMap["name"] = name
  37. ret = append(ret, dataMap)
  38. return ret, nil
  39. }
  40. func HandleOnlineOds1(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  41. dataMapList, err = ParasOds1(msg.Content)
  42. if err != nil {
  43. // 解析不出来数据直接返回
  44. return nil, nil
  45. }
  46. if len(dataMapList) == 0 {
  47. return nil, nil
  48. }
  49. // 入本地库
  50. ods1 := &model.Ods1{}
  51. ods1.Name = dataMapList[0]["name"]
  52. ods1.IdCard = dataMapList[0]["id_card"]
  53. ods1.Content = msg.Content
  54. err = ods1.Insert(clinit.DB())
  55. if err != nil {
  56. if !strings.Contains(err.Error(), "Duplicate") {
  57. return nil, err
  58. }
  59. return nil, nil
  60. }
  61. return dataMapList, nil
  62. }