dro80463 2014-04-24 03:41
浏览 41

连接到Web服务 - 将C#转换为PHP代码

I have a sample code I got from a documentation provided by a merchant. I think the code is in C#. I need to write a code for PHP but I don't have any idea about C# so I'm having a problem with this. I've tried to write a PHP code for this but it doesn't seem right.

By the way, this is a webservice kind of setup and it uses WCF to expose various endpoints. Here's the endpoint they've provided to me: http://services.scorpion.biz/Public/Leads/ExternalLead.svc

Here's the C# code:

public bool SubmitLead(string contactName, string contactNumber) {

    bool outcome = false;
    string message = string.Empty;

    if (contactNumber.Length <= 9) {
        message = "Telephone number is too short";
        outcome = false;
    } else if (contactNumber.Length > 11) {
        message = "Telephone number is too long";
        outcome = false;
    } else if (contactNumber.Length == 10 && contactNumber[0] != '0') {
        message = "Telephone must start with a ZERO";
        outcome = false;
    } else if (contactNumber.Length == 11 && contactNumber.Substring(0, 2) != "27") {
        message = "Telephone must start with a 27";
        outcome = false;
    } else {
        WSExternalLead.LeadRequestMessage request = new
        WSExternalLead.LeadRequestMessage();
        request.Message = “Your Keyword” + ". Contact Name: " + contactName + ".
        Contact Number: " + contactNumber;
        request.TelephoneNumber = contactNumber;
        request.Network = “IMU”;
        request.ReceivedTime = DateTime.Now;

        using (WSExternalLead.ExternalLeadClient client = new WSExternalLead.ExternalLeadClient()) {

            try {
                WSExternalLead.LeadResponseMessage response = null;
                response = client.GenerateLead(request);

                if (response.Result != true) {
                    message = "We were unable to process your request at this
                    time. Error: " + response.ErrorMessage;
                    outcome = false;
                } else {
                    message = "Thank you for your interest in Scorpion Legal
                    Protection. We will get back to you shortly.";
                    outcome = true;
                }
            } catch (FaultException fx) {
                message = "We were unable to process your request at this time.
                Fault: " + fx.Message;
                outcome = false;
            } catch (Exception ex) {
                message = "We were unable to process your request at this time.
                Exception: " + ex.Message;
                outcome = false;
            }
        }
    }

    HttpContext.Current.Session["OUTCOME"] = outcome;
    HttpContext.Current.Session["MESSAGE"] = message;

    return outcome;
}

Here's the PHP code that I've written:

// Read values to variables
$username = $_GET['un'];
$usersurname = $_GET['ul'];
$phonesubmit= $_GET['up'];
$useremail = $_GET['ue'];
$aff_id = $_GET['aff'];
$unique_id = $_GET['uid'];
$rdate = date('m/d/Y G:i:s');
$rdate = date("c", strtotime($rdate));

$wsdlFile = "http://services.scorpion.biz/Public/Leads/ExternalLead.svc?WSDL"; 
$client = new SoapClient($wsdlFile);
$variables->TelephoneNumber = $phonesubmit; 
$variables->Message = "IMU. Name: $username $usersurname. Contact Number: $phonesubmit";
$variables->Network = "IMU";
$variables->ReceivedTime = $rdate;
$result = $client->GenerateLead($variables); 
$returnMessage = $result->Result;
$returnMessage = trim($returnMessage);
if ($returnMessage == ""){
    $returnMessage = $result->ErrorMessage;
}

Any idea on how to solve this would be greatly appreciated. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?