drwpbrv668670 2015-11-26 01:14
浏览 60

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿