duanniwu7730 2018-01-12 00:16
浏览 85

作为发送到Amazon SNS的嵌套信息的一部分,消息响应中出现多个反斜杠-我是否缺少某些内容?

I'm getting the below message response for a golang client script that I've written below to send info to Amazon SNS:

Message response:

{\"recipient\":\"test20@test.com\",\"template\":\"welcome_email_v1\",\"type\":\"email\",\"source\":\"noreply@sender.co\",\"user\":{\"first_name\":\"\\\"tester\\\"\",\"last_name\":\"\\\"M\\\"\"}}"

I'm not quite sure if the multiple backward slashes as part of the nested user hash for first_name and last_name as part of the above message response is normal. Can someone with more experience on this please throw some light if I'm missing something?

package services

import (
  "encoding/json"
  "os"
  "github.com/aws/aws-sdk-go/aws"
  "github.com/aws/aws-sdk-go/aws/session"
  "github.com/aws/aws-sdk-go/service/sns"
)

var NotificationType= "email"

func snsNotificationSender(template, recipient, firstName, lastName string, account_id int) (*sns.PublishOutput, error) {
  sess := session.Must(session.NewSessionWithOptions(session.Options{
      Config: aws.Config{Region: aws.String(os.Getenv("AWS_REGION"))},
      Profile: os.Getenv("AWS_SNS_PROFILE"),
  }))

  svc := sns.New(sess)
  var source string = os.Getenv("EMAIL_SOURCE")

  type UserInfo struct {
    FirstName string `json:"first_name"`
    LastName string `json:"last_name"`
  }

  type MessageBody struct {
    Recipient string `json:"recipient"`
    Template string `json:"template"`
    NotificationType string `json:"type"`
    Source string `json:"source"`
    UserInfo `json:"user"`
  }

  type Message struct {
    MessageBody
  }

  msg := Message{
    MessageBody: MessageBody{
      Template: template,
      Recipient: recipient,
      Source: source,
      NotificationType: NotificationType,
      UserInfo: UserInfo{
        FirstName: firstName,
        LastName: lastName,
      },
    },
  }

  encoded_message, err := json.Marshal(msg)
  message := string(encoded_message)

  msgParams := &sns.PublishInput{
      MessageStructure: aws.String("type: json"),
      Message: aws.String(message),
      TopicArn: aws.String(os.Getenv("AWS_SNS_ARN_Topic")),
  }

  msgResp, err := svc.Publish(msgParams)

  return msgResp, err
}

Thank you.

  • 写回答

1条回答 默认 最新

  • dqch34769 2018-01-12 02:11
    关注

    I had made a mistake in my request end point that hits the SNS client service.

    I had to pass first_name=tester and last_name=M instead of having them as first_name="tester" and last_name="M".

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?