whatsapp.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package aliyun
  2. import (
  3. cams20200606 "github.com/alibabacloud-go/cams-20200606/v2/client"
  4. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  5. "github.com/alibabacloud-go/tea/tea"
  6. )
  7. const (
  8. AccessKeyId string = "LTAI5tSJwCQyuaxXR3UxfnWw"
  9. AccessKeySecret string = "0pv4xhSPJv9IPSxrkB52FspJk27W7V"
  10. RegionId string = "cams.ap-southeast-1.aliyuncs.com"
  11. )
  12. // Description:
  13. // 使用AK&SK初始化账号Client
  14. // @return Client
  15. // @throws Exception
  16. func CreateCamsClient() (_result *cams20200606.Client, _err error) {
  17. // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
  18. // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378661.html。
  19. config := &openapi.Config{
  20. // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
  21. AccessKeyId: tea.String(AccessKeyId),
  22. // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
  23. AccessKeySecret: tea.String(AccessKeySecret),
  24. }
  25. // Endpoint 请参考 https://api.aliyun.com/product/cams
  26. config.Endpoint = tea.String(RegionId)
  27. _result = &cams20200606.Client{}
  28. _result, _err = cams20200606.NewClient(config)
  29. return _result, _err
  30. }
  31. // GetCamsAppId 获取 AppId
  32. // "LTAI5tSJwCQyuaxXR3UxfnWw", "0pv4xhSPJv9IPSxrkB52FspJk27W7V" "cams.ap-southeast-1.aliyuncs.com"
  33. func GetCamsAppId() (string, error) {
  34. client, _err := CreateCamsClient()
  35. if _err != nil {
  36. return "", _err
  37. }
  38. request := &cams20200606.IsvGetAppIdRequest{
  39. Type: tea.String("WHATSAPP"),
  40. }
  41. isvResponse, _err := client.IsvGetAppId(request)
  42. if _err != nil {
  43. return "", _err
  44. }
  45. return *isvResponse.Body.AppId, nil
  46. }
  47. // AddCamsPhoneNumber 添加WhatsApp号码
  48. func AddCamsPhoneNumber(phone, cc, custSpaceId, verifiedName string) (*cams20200606.AddChatappPhoneNumberResponse, error) {
  49. client, _err := CreateCamsClient()
  50. if _err != nil {
  51. return nil, _err
  52. }
  53. request := &cams20200606.AddChatappPhoneNumberRequest{
  54. PhoneNumber: tea.String(phone),
  55. Cc: tea.String(cc),
  56. CustSpaceId: tea.String(custSpaceId),
  57. VerifiedName: tea.String(verifiedName),
  58. }
  59. response, _err := client.AddChatappPhoneNumber(request)
  60. if _err != nil {
  61. return nil, _err
  62. }
  63. return response, nil
  64. }