This commit is contained in:
2022-07-08 08:12:43 +02:00
parent 697b78e3c9
commit 7f5057dc3e
121 changed files with 8039 additions and 19322 deletions

View File

@@ -21,6 +21,7 @@ Public Class cSMS
Property sms_Vorwahl As Object = Nothing
Property sms_Handynummer As Object = Nothing
Property sms_Nachricht As Object = Nothing
Property sms_templateID As Object = Nothing
Property sms_BatchId As Object = Nothing
Property sms_MessageIds As Object = Nothing
Property sms_Uris As Object = Nothing
@@ -73,6 +74,7 @@ Public Class cSMS
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Vorwahl", sms_Vorwahl))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Handynummer", sms_Handynummer))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Nachricht", sms_Nachricht))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_templateID", sms_templateID))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_BatchId", sms_BatchId))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_MessageIds", sms_MessageIds))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sms_Uris", sms_Uris))
@@ -230,7 +232,14 @@ Public Class cSMS
Function sendWhatsApp(Originator As String) As Boolean
'Function sendWhatsApp(Originator As String) As Boolean
' Return sendWhatsAppMessage(Originator)
' 'If sendWhatsAppTemplate(Originator) Then
' ' Return sendWhatsAppMessage(Originator)
' 'End If
' 'Return False
'End Function
Function sendWhatsAppMessage(Originator As String) As Boolean
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim API_STRING = "https://connect.esendex.com"
@@ -267,11 +276,44 @@ Public Class cSMS
Dim json As New Chilkat.JsonObject
'---------------------------------------------
Me.sms_Account = "EX0341154" 'WHATSAPP Account
'Dim successJsonLoad As Boolean = json.Load("
' {
' ""accountReference"": """ & Me.sms_Account & """,
' ""channels"": [
' ""WHATSAPP""
' ],
' ""metadata"":{
' ""key"": ""value""
' },
' ""recipient"": {
' ""address"": {
' ""msisdn"": """ & HandyNr & """
' }
' },
' ""content"": {
' ""body"": {
' ""text"": {
' ""value"": """ & Me.sms_Nachricht & """
' }
' }
' },
' ""channelSettings"": {
' ""sms"": {
' ""originator"": """ & Originator & """,
' ""characterSet"": ""GSM""
' }
' },
' ""expiry"": ""30""
' }")
Dim successJsonLoad As Boolean = json.Load("
{
""accountReference"": """ & Me.sms_Account & """,
""channels"": [
""WhatsApp""
""WHATSAPP""
],
""metadata"":{
""key"": ""value""
@@ -287,14 +329,7 @@ Public Class cSMS
""value"": """ & Me.sms_Nachricht & """
}
}
},
""channelSettings"": {
""sms"": {
""originator"": """ & Originator & """,
""characterSet"": ""GSM""
}
},
""expiry"": ""30""
}
}")
If (successJsonLoad <> True) Then
@@ -306,7 +341,7 @@ Public Class cSMS
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
' MsgBox(sbRequestBody.ToString)
MsgBox(sbRequestBody.ToString)
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST", "/richcontent/v3/send", sbRequestBody, sbResponseBody)
If (success <> True) Then
@@ -333,7 +368,7 @@ Public Class cSMS
Dim Resp_errorCode = jsonResp.StringOf("errorCode")
Me.whatsApp_gatewayId = gatewayId
MsgBox(gatewayId)
If Resp_error <> "" Then Me.whatsApp_error = Resp_error
If Resp_errorCode <> "" Then Me.whatsApp_errorCode = Resp_errorCode
@@ -398,6 +433,186 @@ Public Class cSMS
End Function
Function sendWhatsAppTemplate(Originator As String, template_ParamMFGAdditional As String) As Boolean
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim API_STRING = "https://connect.esendex.com"
Dim rest As New Chilkat.Rest
Dim success As Boolean
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect(API_STRING, port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
Return False
End If
rest.AddHeader("Content-Type", "application/json")
rest.AddHeader("Authorization", API_USER_AUTHORIZATION)
'rest.AddHeader("Accept", "application/vnd.hmrc.1.0+json")
'Dim sbRequestBody As New Chilkat.StringBuilder
'json.EmitSb(sbRequestBody)
Me.sms_art = "WHATSAPP"
Dim mfg = ""
Dim location = ""
Select Case Originator
Case "FRONTOFFICE"
mfg = "VERAG - UNISPED - IMEX"
location = Originator
Case Else
location = Originator
End Select
If template_ParamMFGAdditional <> "" Then
mfg = template_ParamMFGAdditional & " " & mfg
End If
Dim absenderFirma As String = Me.sms_Firma
Dim HandyNr As String = Me.sms_Handynummer.replace(" ", "")
If HandyNr.ToString.StartsWith("00") Then HandyNr = "+" & HandyNr.Substring(2)
If Originator = "" Then Originator = absenderFirma
If Originator.Length > 11 Then Originator = Originator.Substring(0, 11)
Dim json As New Chilkat.JsonObject
'---------------------------------------------
Me.sms_Account = "EX0341154" 'WHATSAPP Account
' Dim TemplateId = "e5c1ce77-31a0-4663-9576-be340f73ac1c"
Dim successJsonLoad As Boolean = json.Load("
{
""accountReference"": """ & Me.sms_Account & """,
""channels"": [
""WHATSAPP""
],
""metadata"":{
""key"": ""value""
},
""recipient"": {
""variables"": {
""mfg"": """ & mfg & """,
""location"": """ & location & """
},
""address"": {
""msisdn"": """ & HandyNr & """
}
},
""content"": {
""templateId"": """ & Me.sms_templateID & """
}
}")
If (successJsonLoad <> True) Then
' MsgBox(json.LastErrorText)
Return False
End If
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
'MsgBox(sbRequestBody.ToString)
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST", "/richcontent/v3/send", sbRequestBody, sbResponseBody)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Return False
End If
Dim respStatusCode As Integer = rest.ResponseStatusCode
Me.whatsApp_status = respStatusCode ' 202 = OK - Gesendet
If (respStatusCode <> 202) Then
MsgBox(sbResponseBody.GetAsString())
Return False
End If
Dim jsonResp = New Chilkat.JsonObject()
jsonResp.LoadSb(sbResponseBody)
Dim gatewayId = jsonResp.StringOf("gatewayId")
Dim Resp_error = jsonResp.StringOf("error")
Dim Resp_errorCode = jsonResp.StringOf("errorCode")
Me.whatsApp_gatewayId = gatewayId
' MsgBox(gatewayId)
If Resp_error <> "" Then Me.whatsApp_error = Resp_error
If Resp_errorCode <> "" Then Me.whatsApp_errorCode = Resp_errorCode
' MsgBox(gatewayId)
If Not Me.SAVE() Then
MsgBox("Fehler: WHATSAPP Daten wurden nicht gespeichert!")
End If
Return True
'productTitle = json.StringOf("product.title");
'productBody_html = json.StringOf("product.body_html");
'productVendor = json.StringOf("product.vendor");
'productProduct_type = json.StringOf("product.product_type");
'productCreated_at = json.StringOf("product.created_at");
'productHandle = json.StringOf("product.handle");
'productUpdated_at = json.StringOf("product.updated_at");
'productPublished_at = json.IsNullOf("product.published_at");
'productTemplate_suffix = json.IsNullOf("product.template_suffix");
'productPublished_scope = json.StringOf("product.published_scope");
'productTags = json.StringOf("product.tags");
'productImage = json.IsNullOf("product.image");
'i = 0;
'count_i = json.SizeOfArray("product.variants");
'while (i < count_i) {
' json.I = i;
' id = json.IntOf("product.variants[i].id");
' product_id = json.IntOf("product.variants[i].product_id");
' title = json.StringOf("product.variants[i].title");
' price = json.StringOf("product.variants[i].price");
' sku = json.StringOf("product.variants[i].sku");
' position = json.IntOf("product.variants[i].position");
' grams = json.IntOf("product.variants[i].grams");
' inventory_policy = json.StringOf("product.variants[i].inventory_policy");
' compare_at_price = json.IsNullOf("product.variants[i].compare_at_price");
' fulfillment_service = json.StringOf("product.variants[i].fulfillment_service");
' inventory_management = json.IsNullOf("product.variants[i].inventory_management");
' option1 = json.StringOf("product.variants[i].option1");
' option2 = json.IsNullOf("product.variants[i].option2");
' option3 = json.IsNullOf("product.variants[i].option3");
' created_at = json.StringOf("product.variants[i].created_at");
' updated_at = json.StringOf("product.variants[i].updated_at");
' taxable = json.BoolOf("product.variants[i].taxable");
' barcode = json.IsNullOf("product.variants[i].barcode");
' image_id = json.IsNullOf("product.variants[i].image_id");
' inventory_quantity = json.IntOf("product.variants[i].inventory_quantity");
' weight = json.IntOf("product.variants[i].weight");
' weight_unit = json.StringOf("product.variants[i].weight_unit");
' old_inventory_quantity = json.IntOf("product.variants[i].old_inventory_quantity");
' requires_shipping = json.BoolOf("product.variants[i].requires_shipping");
' i = i + 1;
'}
Return True
Catch ex As Exception
MsgBox("Fehler beim Senden der WhatsApp-SMS!" & vbNewLine & ex.Message & ex.StackTrace)
Return False
End Try
End Function
Function checkSMSStatus(Optional silent = False, Optional insertVermerkAviso = True) As String
Try
@@ -467,6 +682,7 @@ Public Class cSMS
Function checkWhatsAppStatus(Optional silent = False, Optional insertVermerkAviso = True) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Select Case Me.sms_Status
@@ -485,7 +701,6 @@ Public Class cSMS
Dim API_STRING = "https://connect.esendex.com"
Dim rest As New Chilkat.Rest
@@ -523,7 +738,7 @@ Public Class cSMS
'Fehler --> --> FALLBACK SMS!!!
If DateDiff(DateInterval.Minute, Me.sms_Datum, Now) > 10 Then
Me.FALLBACK_SMS
Me.FALLBACK_SMS()
End If
@@ -531,12 +746,13 @@ Public Class cSMS
If Not silent Then MsgBox("Error: " & respStatusCode)
Return Me.sms_Status
End If
Dim jsonResp = New Chilkat.JsonObject()
jsonResp.LoadSb(sbResponseBody)
' MsgBox(sbResponseBody.ToString)
' MsgBox(sbResponseBody.ToString)
Dim allowVermerk = True
Dim lastUpdatedUtc = jsonResp.StringOf("lastUpdatedUtc")
@@ -605,6 +821,7 @@ Public Class cSMS
Sub FALLBACK_SMS()
'--> FALLBACK SMS!!!
Me.sms_art = "SMS"
Me.sms_Account = GET_AccountByAbsFirma(Me.sms_Firma) ' Ändern, da WhatsApp Account nciht in TR freigeschaltet ist.
Me.sms_Status = -1
Me.sendSMS()
Me.SAVE()
@@ -663,6 +880,23 @@ Public Class cSMS
End Sub
Shared Function GET_AccountByAbsFirma(absenderFirma)
Select Case absenderFirma'cboFirma._value
Case "VERAG Spedition" : Return "EX0252513"
Case "VERAG 360" : Return "EX0252747"
Case "ATILLA Spedition" : Return "EX0252746"
Case "IMEX Spedition" : Return "EX0272082"
Case "UNISPED Spedition" : Return "EX0300174"
Case "FRONT-OFFICE SUBEN" : Return "EX0300173"
Case "AMBAR" : Return "EX0315223"
Case Else : Return "EX0300173"
End Select
End Function
End Class