首页 手机话费充值 手机话费充值示例代码 话费充值异步通知[PHP]

话费充值异步通知示例代码[PHP]

作者: 阅读数:2573 上传时间:

话费充值异步通知

<?php

/**
 * 异步回调
 *
 */

$orderno = $_POST['orderno'];
$rechargestatus = $_POST['rechargestatus'];
$arr = array('orderno'=>$orderno,'outorderno'=>$_POST['outorderno'],'mobile'=>$_POST['mobile'],'rechargestatus'=>$_POST['rechargestatus'],'amount'=>$_POST['amount'],'totalfee'=>$_POST['totalfee']);
$appsecret = '123456789';//用户appsecret
if(checkSign($arr, $appsecret, $_POST['sign']))
{
    //1成功 2充值失败 0充值中
    switch($rechargestatus)
    {        
        case '1': 
        {
            //充值成功
            //            
            break;
        }
        case '2':
        {
            //充值失败
            break;
        }
    }
    
    if($rechargestatus != 0) echo 'success';
    exit();
}

/**
 * 验证签名 
 * 
 */
function checkSign($queryarr, $appsecret, $signature)
{    
    $str = makeSign($queryarr, $appsecret);
    if($str == strtolower($signature)) return true;
    else return false;
}

/**
 * 生成签名 
 * 
 */
function makeSign($queryarr, $appsecret)
{
    ksort($queryarr, SORT_STRING);
    $str = implode($queryarr);
    $str .= $appsecret;
    //exit($str);
    $str = md5($str);
    
    return $str;
}