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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 蓝牙耳机怎么查看日志
    • ¥15 R语言 拟时序分析降维图如何减少分支
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统