HTTPS URL在PHP中不起作用

时间:2017-02-18 06:49:38

标签: xml https

我正在SMS Project的网上购物商店工作,目的是当客户下订单时,系统应该在结账时自动发送客户提供的号码短信。

SMS公司为此提供API文档。首先,他们需要生成会话ID的身份验证过程,我们使用会话ID向用户发送短信。

验证码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="bd.tahsincom.smartsell.MainActivity"
    tools:showIn="@layout/activity_main2">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

现在问题是我无法获得会话ID。当我使用$msisdn = 'abc'; $password = 'xyz'; $session_req="https://telenorcsms.com.pk:27677/corporate_sms2/api/auth.jsp?msisdn=".$msisdn."&password=".$password; $xmlResponse = simplexml_load_file('https://telenorcsms.com.pk:27677/corporate_sms2/api/auth.jsp?msisdn=abc&password=xyz'); $sessionID = $xmlResponse->corpsms->data; var_dump($sessionID); echo "Session ID: " . $sessionID; 而不是输出NULL时,如果我尝试使用var_dump($sessionID);在屏幕上显示,则显示任何内容。如果我使用echo "Session ID: " . $sessionID;代码而不是以下代码是上述网址的响应并成功显示会话ID。

成功回应:

header('Location:'.$session_req);

会话ID存储在XML结构中,并且存储在不同的URL中,但我的文件位于不同的URL。 (http://example.com/neworder.php)。 任何人都可以让我知道如何将会话ID存储在PHP中的变量中以进一步使用它来发送短信? 重要的一点是会话ID将在30分钟不活动后过期。 以下是使用会话ID发送短信的URL:

<?xml version="1.0" encoding="UTF-8" ?> 
<corpsms> 
    <command>Auth_request</command> 
    <data>Session ID</data> 
    <response>OK</response>
</corpsms>

提前感谢。

MUNEEB

2 个答案:

答案 0 :(得分:0)

  • 将XML响应存储到PHP变量中(我们称之为 $ xmlResponse
  • 通过将与其参数关联的API网址提交到 DataFrame.mean 功能,您可以轻松获得XML响应。然后使用函数file_get_contents()

    将其转换为XML对象
    $sessionID = $xmlResponse->corpsms->data;
    
  • 该回复可以用作simplexml_load_string()

  • 应以这种方式访问​​会话ID:

    public static void main(String [] args)
    {
        System.out.println(answer(200));
    }
    public static int answer(int n) { 
        return bricks(1,n) -1;
    }
    public static int bricks(int height, int bricksLeft)
    {
        if(bricksLeft == 0)
        {
            return 1;
        }
        else if(bricksLeft < height)
        {
            return 0;
        }
        else
        {
            return bricks(height +1, bricksLeft - height) + bricks(height +1, bricksLeft);
        }
    }
    

答案 1 :(得分:0)

我在hostgator服务器上执行脚本时遇到了同样的问题,但它在我的localhost服务器上运行正常。你只需要在WAMP或XAMP服务器中启用OPENSSL扩展。