ods15.go 2.2 KB

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