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 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器