選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

55 行
1.0KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. )
  7. type crmdLocation struct {
  8. crmdEntityBase
  9. Latitude float64 `json:"latitude"`
  10. Longtitude float64 `json:"longtitude"`
  11. Precision float64 `json:"precision"`
  12. LeadID string `json:"leadId,omitempty"`
  13. }
  14. //record location
  15. func onLocation(in InWechatMsg) {
  16. openID := in.header.FromUserName
  17. lead, found, err := crmFindLeadByOpenID(openID)
  18. if found && err == nil {
  19. e := in.body.(EventMsg)
  20. //save info
  21. info := crmdLocation{}
  22. info.Name = in.header.FromUserName
  23. info.LeadID = lead.ID
  24. info.Longtitude = e.Longitude
  25. info.Latitude = e.Latitude
  26. info.Precision = e.Precision
  27. info.Save()
  28. }
  29. }
  30. func (m crmdLocation) Save() (location crmdLocation, err error) {
  31. jsonB, err := json.Marshal(m)
  32. if err != nil {
  33. log.Println(err)
  34. return
  35. }
  36. entity, err := crmCreateEntity("Location", jsonB)
  37. if err != nil {
  38. log.Println(err)
  39. return
  40. }
  41. location, ok := entity.(crmdLocation)
  42. if !ok {
  43. err = errors.New("incorrect entity cannot convert to Location")
  44. }
  45. log.Println(location)
  46. return
  47. }