SMS支付API集成

Hi i need to integrate sms payments into site, hide element or link behind paywall, i have everything i need from company that backs these sms payments as well as text saying that the integration into site is fast and easy but for christs sake i have no idea how to make it work. i need to create this simple input for recieved sms code:

IMAGE

what i got from company is this guide:

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"}
__________________________

And these two sample demo codes:

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);

SECOND:

<?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);

Can anyone help me/guide me with implementing this into site, as i already said i want to "hide" either element of site behind this paywall or link, thanks in advance :)

doude4924
doude4924 如果你能写出你自己雇用的代码。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问