首页 加油卡充值 加油卡充值示例代码 加油卡异步通知[PHP]

加油卡异步通知示例代码[PHP]

作者: 阅读数:1576 上传时间:2017-05-09

加油卡异步通知

<?php

$orderno = $_POST['orderno'];
$rechargestatus = $_POST['rechargestatus'];
$arr = array('orderno'=>$orderno,'outorderno'=>$_POST['outorderno'],'fuelcard'=>$_POST['fuelcard'],'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;
}