vba を使用して、取得したテキスト メッセージ情報をクライアントに投稿する POST 関数を設定しています。私はコール センターで働いているので、通話が終了したら、テキスト メッセージを自動的に送信するクライアントにデータを送信する必要があります。
Curl を使用する PHP で記述されたクライアントからサンプル API を受け取りました。これをvbaに変換しようとしています。
phpコードは次のとおりです。
`public function SendSingleSMS($user, $pass, $mobile, $originator, $innerMessage, $messageType)
{
//Send Data
$fields = array
(
'user' => $user,
'pass' => $pass,
'func' => 8,
'mobile' => $mobile,
'orig' => $originator,
'msg' => urlencode($innerMessage),
'msgType' => $messageType
);
$response = $this->sendUsingCURL($this->apiURL, $fields);
return $response;
}
//Send information
private function sendUsingCURL($url, $fields)
{
//url-ify the data for the POST
foreach($fields as $key=>$value)
$fields_string .= $key.'='.$value.'&';
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//WARNING: this would prevent curl from detecting a 'man in the middle' attack
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if($response === false)
throw new Exception(__CLASS__."::".__FUNCTION__."_".$err);
return $response;
}
}`
私はすべてを試し、すべての検索を行いました。エラーなしでこのサービスにvbaを投稿できないようです。
vba コード:
Dim oHttp As Object
Dim strServer, strUsername, strPassword, strMessage, strMobileNumber, strData As String
Set oHttp = CreateObject("Microsoft.XMLHTTP")
'-- get message paramaters from screen fields
strUsername = "user"
strPassword = "pass"
strfunc = "8"
strmobile = "0773432111"
strorig = "71111"
strmsg = "HelloWorld"
strmsgtype = "4"
'-- build the HTTP POST dataset
strData = "&user=" + strUsername + "&pass=" + strPassword + "&func=" + strfunc + "&mobile=" + strmobile + "&orig=" + strorig + "&msg=" + strmsg + "&msgType=" + strmsgtype
'-- prepare the HTTP POST message
oHttp.Open "POST", "http://test.com/API/Link.php", False
oHttp.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.setRequestHeader "Accept", "*/*"
oHttp.setRequestHeader "Content-Length", CStr(Len(strData))
oHttp.setRequestHeader "Connection", "close"
'-- send the message
oHttp.send (strData)
Text0 = strData
'-- get the response
MsgBox (oHttp.responseText)
VBA に curl 投稿と同様のデータを投稿させる方法はありますか? 私が試したすべてのことで、間違ったログイン情報、またはエラーが表示されます。
「メッセージに互換性のない文字が見つかりました。GSM 互換の文字のみを使用してください (非標準のアポストロフィとダッシュが原因です)」