APP Development of Wotoken Wallet System

Keywords: PHP Mobile JQuery less

Since the launch of Alibaba, the Wotoken wallet system APP has developed T:/ I8O-2853-296O differentiable + many short message platforms, which are close to death. Alibaba is a product of Alibaba, a big brand and a low rate, so many individual webmasters have joined it (not advertising....).

A short message is less than 5 cents, so it is suggested to add the function of short message registration to the website to lock users more accurately.

Next, I will share with you an interface that Ali is bigger than SMS.

First create a send model (Send.php):

<?php
namespace appindexmodel;
use thinkValidate;
class Send extends thinkModel
{

public static $sms_config = [
    'appkey'        => '',//Ali is bigger than APPKEY
    'secretKey'     => '',//Ali is bigger than secretKey
    'FreeSignName'     => 'Ander Rabbit',//Short Message Signature
];
public function sms($data=[])
{
    $validate = new Validate([
        ['param','require|array','Parameters must be filled in|The parameters must be arrays'],
        ['mobile','require|/1[34578]{1}\d{9}$/','Error in mobile number|Error in mobile number'],
        ['template','require','Template id error'],
    ]);
    if (!$validate->check($data)) {
        return $validate->getError();
    }
    define('TOP_SDK_WORK_DIR', CACHE_PATH.'sms_tmp/');
    define('TOP_SDK_DEV_MODE', false);
    vendor('alidayu.TopClient');
    vendor('alidayu.AlibabaAliqinFcSmsNumSendRequest');
    vendor('alidayu.RequestCheckUtil');
    vendor('alidayu.ResultSet');
    vendor('alidayu.TopLogger');
    $config = self::$sms_config;
    $c = new \TopClient;
    $c->appkey = $config['appkey'];
    $c->secretKey = $config['secretKey'];
    $req = new \AlibabaAliqinFcSmsNumSendRequest;
    $req->setExtend('');
    $req->setSmsType('normal');
    $req->setSmsFreeSignName($config['FreeSignName']);
    $req->setSmsParam(json_encode($data['param']));
    $req->setRecNum($data['mobile']);
    $req->setSmsTemplateCode($data['template']);
    $result = $c->execute($req);
    $result = $this->_simplexml_to_array($result);
    if(isset($result['code'])){
        return $result['sub_code'];
    }
    return true;
}

private function _simplexml_to_array($obj)
{//This function is used to transform Ali greater than the returned data, simplexml format into arrays, aspect follow-up use
    if(count($obj) >= 1){
        $result = $keys = [];
        foreach($obj as $key=>$value){
            isset($keys[$key]) ? ($keys[$key] += 1) : ($keys[$key] = 1);
            if( $keys[$key] == 1 ){
                $result[$key] = $this->_simplexml_to_array($value);
            }elseif( $keys[$key] == 2 ){
                $result[$key] = [$result[$key], $this->_simplexml_to_array($value)];
            }else if( $keys[$key] > 2 ){
                $result[$key][] = $this->_simplexml_to_array($value);
            }
        }
        return $result;
    }else if(count($obj) == 0){
        return (string)$obj;
    }
}

}
?>
Once the model is created, it can be invoked elsewhere. Let's create a simple index controller for testing:

<?php
namespace appindexcontroller;
use appindexmodelSend;
error_reporting(0);
class Index extends thinkController
{

public function sms()
{
    if(request()->isPost()){
        $Send = new Send;
        $result = $Send->sms([
            'param'  => ['code'=>'123456','product'=>'Ander Rabbit'],
            'mobile'  => input('post.mobile/s','','trim,strip_tags'),
            'template'  => 'SMS_12940581',
        ]);
        if($result !== true){
            return $this->error($result);
        }
        return $this->success('Successful text messaging!');
    }
    return $this->fetch();
}

}
Create a simple template file to test:

<!doctype html>
<html lang="zh-CN">
<head>

<meta charset="utf-8">
<title>Ali Bigger Text Sending Test</title>
<base href="{:request()->domain()}" />
<link href="static/css/bootstrap.css" rel="stylesheet">
<link href="static/css/common.css" rel="stylesheet">
<link href="static/css/admin.css" rel="stylesheet">
<script src="static/js/jquery-1.12.0.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/jquery.qrcode.min.js"></script>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>

</head>
<body>
<div class="container">

<div class="panel panel-default">
    <div class="panel-heading">
        <strong>Ali Bigger Text Sending Test</strong>
    </div>
    <div class="panel-body">
        <form class="form-horizontal sms-form" method="post" action="{:url('index/index/sms')}">
            <div class="form-group">
                <label class="col-sm-2 control-label">Receiving mobile phone number</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="mobile" value="">
                    <p class="help-block">Click Send SMS, you will receive: "[Ander Rabbit] Verification Code 123456, you are registering as Ander Rabbit user, thank you for your support."</p>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-success">Send short messages</button>
                </div>
            </div>
        </form>
    </div>
    <div class="panel-footer">&nbsp;</div>
</div>

</div>
<script>

$(function(){
    $('.sms-form').submit(function(){
        var $this = $(this);
        if(!$this.hasClass('lock-form')){
            $this.addClass('lock-form');//Lock the form
            var formData = new FormData($this[0]);
            $.ajax({
                url:$this.attr("action"),
                type:'POST',
                data:formData,
                dataType:'json',
                cache: false,
                contentType: false,
                processData: false,
                success:function(s){
                    $this.removeClass('lock-form');//Unlock forms
                    var html = (s.code != 1 ? 'Error code:' : '')+s.msg;
                    $('.panel-footer').html(html);
                    return false;
                }
            });
        }
        return false;
    });
});

</script>
</body>
</html>

Posted by shane18 on Wed, 09 Oct 2019 20:27:14 -0700