博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php微信支付回调验证
阅读量:4691 次
发布时间:2019-06-09

本文共 2111 字,大约阅读时间需要 7 分钟。

//字典排序拼接字符串function getWxPaySignature($arr){    ksort($arr);    $str = '';    foreach ($arr as $k=>$a){        $str .= $k;        $str .= '='.$a.'&';    }    $str = trim($str,'&');    return $str;}//微信回调验证function weCallbackCheck($xml){    $sign = $xml->sign;    $appid = $xml->appid;    $bank_type = $xml->bank_type;    $cash_fee = $xml->cash_fee;    $fee_type = $xml->fee_type;    $is_subscribe = $xml->is_subscribe;    $mch_id = $xml->mch_id;    $nonce_str = $xml->nonce_str;    $openid = $xml->openid;    $out_trade_no = $xml->out_trade_no;    $result_code = $xml->result_code;    $return_code = $xml->return_code;    $time_end = $xml->time_end;    $total_fee = $xml->total_fee;    $trade_type = $xml->trade_type;    $transaction_id = $xml->transaction_id;    $device_info = $xml->device_info;    $signArr = array(        'appid' => "$appid",        'bank_type' => "$bank_type",        'cash_fee' => "$cash_fee",        'device_info' => "$device_info",        'fee_type' => "$fee_type",        'is_subscribe' => "$is_subscribe",        'mch_id' => "$mch_id",        'nonce_str' => "$nonce_str",        'openid' => "$openid",        'out_trade_no' => "$out_trade_no",        'result_code' => "$result_code",        'return_code' => "$return_code",        'time_end' => "$time_end",        'total_fee' => "$total_fee",        'trade_type' => "$trade_type",        'transaction_id' => "$transaction_id"    );    foreach ($signArr as $key => $value) {        if($value == ''){            unset($signArr[$key]);        }    }    $stringA = getWxPaySignature($signArr);//数组字典排序拼接字符串    $stringSignTemp = $stringA.'&key=???';//设置的key    $signValue = md5($stringSignTemp);    $signValue = strtoupper($signValue);    if($signValue == $sign){        return 'success';//支付成功    }else{     file_put_contents('failure.txt',json_encode($signArr).PHP_EOL,FILE_APPEND);        return 'failure';    }}$xmlstr = file_get_contents("php://input");$xml=simplexml_load_string($xmlstr, 'SimpleXMLElement', LIBXML_NOCDATA);if(weCallbackCheck($xml)=="success"){    echo "支付成功";}

  

转载于:https://www.cnblogs.com/mracale/p/9437829.html

你可能感兴趣的文章
初识 Entity FrameWork 5 Enum
查看>>
浅谈javascript函数节流
查看>>
幂取模运算图示
查看>>
把.net中ViewState的隐藏内容调整到网站的底部
查看>>
10.30作业.
查看>>
python作业 20181204
查看>>
hdu2660 Accepted Necklace (DFS)
查看>>
C的xml编程文章链接
查看>>
oracle触发器中增删改查本表
查看>>
怎样处理iOS 5与iOS 6的 low-memory
查看>>
Sprite图像拼合技术优缺点
查看>>
ASOC驱动框架分析
查看>>
单元测试 学习笔记 之四
查看>>
反射RelectionDemo
查看>>
CGI概念
查看>>
Ponds
查看>>
元类metaclass
查看>>
Xcode7企业版打包
查看>>
hashCode equals hashSet
查看>>
c#(.net) 导出 word表格
查看>>