SMS支付API集成

时间:2015-11-26 01:14:31

标签: php api sms integration

您好我需要将短信付款整合到网站,隐藏元素或付费墙后面的链接,我有我需要的一切,支持这些短信付款的公司以及文字说,整合到网站是快速和容易,但为了基督的缘故我不知道如何使它工作。我需要为收到的短信代码创建这个简单的输入:

IMAGE

我从公司获得的是本指南:

2. Receiving MO SMS, Sending MT SMS

Receiving MO SMS and sending MT SMS is handled by one HTTP POST
request and response.

Workflow:

1. A SMS sends MO SMS envelope object to client

2. Client responses with MT SMS envelope object back immediately

Objects are JSON objects.

MO SMS Envelope

Name Type Description

mosms MO SMS Object MO SMS

MO SMS Object
Name Type Required Description
id int Required Unique ID of MO SMS
dst_no string Required Destination short number – e.g. 8877
src_no string Required Source phone number of customer in international
format only +421903123456
gtw_type int Required Mobile operator code
23101 – Orange SK
23102 – Telekom SK
23106 – O2 SK
other
message string Required Message – UTF8 encoding, unlimited characters
(multipart SMS)
hash string Required Hex (lowercase) encoded SHA1 HMAC from (id +
src_no + dst_no + gtw_type + message)
MT SMS Envelope
Name Type Description
status string ok, error
mtsms MT SMS object MT SMS
MT SMS Object
Name Type Required Description
message string Required Text message, max. 160 characters, GSM7
alphabet ASCII encoded, required
bill_key string Required Dedicated billing code, e.g. MYPAY-00-00,
required
hash string Required Hex (lowercase) encoded SHA1 HMAC from
(message + bill_key)
________________________________________________________________________________


3. MT SMS statuses
Workflow:
1. A SMS sends Status envelope object to client
2. Client responses back immediately
Objects are JSON objects.
Status Envelope
Name Type Description
mtstatus Status object Status
Status Object
Name Type Required Description
id int Required Unique ID of MO SMS
status string Required Billing/delivery status
hash string Required Hex (lowercase) encoded SHA1 HMAC from (id +
status)
Statuses:
D – Billed AND delivered
S – Billed
E – NOT billed and NOT delivered
U – NOT delivered
Status response Envelope
Name Type Description
status string ok, error
________________________________________________________________________________


4. Examples
1. HTTP POST – MO and MT SMS
Request
ASMS -----------> Client
{"mosms": {"message": "Test", "gtw_type": 23106, "id": 123, "src_no":
"+421903123456", "dst_no": "8877", "hash": "xxx"}}
Response
Client -----------> ASMS
{"status":"ok", "mtsms":{"message": "test mt sms", "bill_key": "MYPAY-
00-00", "hash": "xxx"}}
{"status":"error", "mtsms":null}
2. HTTP POST – Billing/Delivery status
Request
ASMS -----------> Client
{"mtstatus": {"id": 123, "status": "D", "hash": "xxx"}}
Response
Client -----------> ASMS
{"status":"ok"}
{"status":"error"}
__________________________

这两个示例代码:

FIRST:

<?php

define('CONFIG_HASH_KEY', 'ABCDEFGH');

try {

        // read json data
        $postdata = file_get_contents("php://input");
        $json = json_decode($postdata);
        $mosms = $json->mosms;

        // check hash
        $hashedStr = $mosms->id . $mosms->src_no . $mosms->dst_no . $mosms->gtw_type . $mosms->message;
        $hashedStr = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY);
        if($hashedStr != $mosms->hash) {
                throw new Exception('Hash error');
        }

        ////////////////////////////////////////////////////////////////////
        // process SMS
        // your code

        // response example
        $response = array(
                'status' => 'ok',
                'mtsms' => array(
                        'message' => 'Dakujeme za platbu',
                        'bill_key' => 'MYPAY-01-00',
                ),
        );

        // or
        $response = array(
                'status' => 'ok',
                'mtsms' => array(
                        'message' => 'SMS ste nenapisali v spravnom formate, prosim opravte sa...',
                        'bill_key' => 'MYPAY-00-00',
                ),
        );

        ////////////////////////////////////////////////////////////////////

        $hashedStr = $response['mtsms']['message'] . $response['mtsms']['bill_key'];
        $response['mtsms']['hash'] = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY);


}
catch(Exception $e) {                
        $response = array(
                'status' => 'error',
                'mtsms' => null,
        );
}

echo json_encode($response);

第二

<?php

define('CONFIG_HASH_KEY', 'ABCDEFGH');

try {

        // read json data
        $postdata = file_get_contents("php://input");
        $json = json_decode($postdata);
        $mtstatus = $json->mtstatus;

        // check hash
        $hashedStr = $mtstatus->id . $mtstatus->status;
        $hashedStr = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY);
        if($hashedStr != $mtstatus->hash) {
                throw new Exception('Hash error');
        }

        ////////////////////////////////////////////////////////////////////
        // process status
        // your code

        if($mtstatus->status === 'D') {
                //SMS was billed and delivered
        }
        else if($mtstatus->status === 'E') {
                //SMS was NOT billed and delivered
        }
        else if($mtstatus->status === 'S') {
                //SMS was billed
        }
        else if($mtstatus->status === 'U') {
                //SMS was NOT  delivered
        }


        // response example
        $response = array(
                'status' => 'ok'
        );


        ////////////////////////////////////////////////////////////////////

}
catch(Exception $e) {                
        $response = array(
                'status' => 'error'
        );
}

echo json_encode($response);

任何人都可以帮助我/指导我将其实施到网站中,因为我已经说过我想要隐藏&#34;这个付费墙或链接后面的网站元素,提前谢谢:)

0 个答案:

没有答案