油卡话费通道
Posted 逆天而行
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了油卡话费通道相关的知识,希望对你有一定的参考价值。
<?php
/**
- Created by PhpStorm.
- Date: 2019-04-03
- Time: 12:00
*/
namespace Pay\\Controller;
class YkhfController extends PayController
{
public function __construct()
{
parent::__construct();
}
//支付
public function Pay($array)
{
$orderid = I("request.pay_orderid");
$body = I(\'request.pay_productname\');
$parameter = array(
\'code\' => \'Ykhf\', // 通道名称
\'title\' => \'油卡话费\',
\'exchange\' => 1, // 金额比例
\'gateway\' => \'\',
\'orderid\' => \'\',
\'out_trade_id\' => $orderid,
\'body\' => $body,
\'channel\' => $array,
);
// 订单号,可以为空,如果为空,由系统统一的生成
$return = $this->orderadd($parameter);
$return[\'subject\'] = $body;
//如果生成错误,自动跳转错误页面
$return["status"] == "error" && $this->showmessage($return["errorcontent"]);
//跳转页面,优先取数据库中的跳转页面
$return["notifyurl"] || $return["notifyurl"] = $this->_site . \'Pay_Ykhf_notifyurl.html\';
$return[\'callbackurl\'] || $return[\'callbackurl\'] = $this->_site . \'Pay_Ykhf_callbackurl.html\';
error_reporting(0);
header("Content-type: text/html; charset=utf-8");
$mchid = $return["mch_id"]; //商户ID
$orderId = $return[\'orderid\']; //订单号,需要保证唯一,不可重复提交相同订单ID
$amount = (int)$return[\'amount\']; //交易金额
$notifyUrl = $return["notifyurl"] ; //服务端返回地址
// $uid = $return[\'appsecret\']; //UID
$payType = $return[\'appid\']; //银行编码
$key = $return[\'signkey\']; //密钥
$apiUrl = \'http://www.limenghome.cn/api/pay \'; //提交地址
$sData = array(
\'mchid\' => $mchid,
\'mch_order_id\' => $orderId,
\'price\' => $amount,
\'paytype\' => $payType,
\'notify\' => $notifyUrl,
\'time\' => time(),
\'rand\' => mt_rand(100000, 999999),
);
$str = md5($sData[\'mchid\'].$sData[\'mch_order_id\'].$sData[\'price\'].$sData[\'paytype\'].$sData[\'notify\'].$sData[\'time\'].$sData[\'rand\']. $key);
$sign = $str;
$sData["sign"] = $sign;
$return = $this->post($apiUrl, $sData);
if (!$return) {
$this->showmessage(\'网络故障,请联系客服。\');
}
$return=json_decode($return,true);
if ($return[\'code\'] == \'0\') {
$qrcode=$return[\'data\'][\'url\'];
header("Location:" . $qrcode);
}else {
$this->showmessage($return[\'msg\']);
}
}
//同步通知(此通道没回调)
public function callbackurl()
{
$Order = M("Order");
$pay_status = $Order->where([\'pay_orderid\' => $_REQUEST["order_id"]])->getField("pay_status");
$callbackurl = $Order->where([\'pay_orderid\' => $_REQUEST["order_id"]])->getField("pay_callbackurl");
//var_dump($callbackurl);die;
if ($pay_status <> 0) {
$this->EditMoney($_REQUEST[\'order_id\'], \'Yz\', 1);
header("location:$callbackurl");
die;
exit(\'交易成功!\');
} else {
header("location:$callbackurl");
die;
}
}
//异步通知
public function notifyurl()
{
if(empty($_REQUEST)){
$input = file_get_contents(\'php://input\');
if(!empty($input)){
$_REQUEST = json_decode($input,true);
}
}
$fileName = \'Ykhf\';
$logName = \'logname.html\';
// 向后追加,回调记录数据
file_put_contents($logName, \'<br/>\'.$fileName.\'[\'.date(\'Y-m-d H:i:s\',time()).\']REQUEST[notify]\'.json_encode($_REQUEST).\'<br/>\',FILE_APPEND);
file_put_contents($logName, \'<br/>\'.$fileName.\'[\'.date(\'Y-m-d H:i:s\',time()).\']get[notify]\'.json_encode($_GET).\'<br/>\',FILE_APPEND);
file_put_contents($logName, \'<br/>\'.$fileName.\'[\'.date(\'Y-m-d H:i:s\',time()).\']post[notify]\'.json_encode($_POST).\'<br/>\',FILE_APPEND);
file_put_contents($logName, \'<br/>\'.$fileName.\'[\'.date(\'Y-m-d H:i:s\',time()).\']input[notify]\'.$input.\'<br/>\',FILE_APPEND);
$md5key=getKey($_REQUEST[\'mch_order_id\']);
$pData = [
\'mchid\' => $_REQUEST[\'mchid\'], //下单传入的订单号
\'mch_order_id\' => $_REQUEST[\'mch_order_id\'], //平台交易流水订单号
\'pt_order_id\' => $_REQUEST[\'pt_order_id\'], //订单金额
\'price\' => $_REQUEST[\'price\'], //付款通道
\'paytype\' => $_REQUEST[\'paytype\'], //付款时间
\'status\' => $_REQUEST[\'status\'], //收款APP账号
];
$sign = md5($pData[\'mchid\'].$pData[\'mch_order_id\'].$pData[\'pt_order_id\'].$pData[\'price\'].$pData[\'paytype\'].$pData[\'status\']. $md5key);
if($sign == $_REQUEST[\'sign\']){
if($_REQUEST[\'status\'] ==1){
$this->EditMoney($_REQUEST[\'mch_order_id\'], $fileName, 0);
echo "success";
exit;
}else{
//验证失败
echo "FAIL";
exit;
}
}else{
//验证失败
echo "sign_FAIL";
exit;
}
}
public function post($url, $data){//file_get_content
$postdata = http_build_query(
$data
);
$opts = array(\'http\' =>
array(
\'method\' => \'POST\',
\'header\' => \'Content-type: application/x-www-form-urlencoded\',
\'content\' => $postdata,
\'timeout\'=>10,//单位秒
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
}
以上是关于油卡话费通道的主要内容,如果未能解决你的问题,请参考以下文章
PHP话费充值通道网站完整运营源码/全解密无授权/对接免签约支付接口
SpringCloud系列十一:SpringCloudStream(SpringCloudStream 简介创建消息生产者创建消息消费者自定义消息通道分组与持久化设置 RoutingKey)(代码片段
TSINGSEE青犀视频通道FFmpeg获取视频片段的方法介绍
错误记录Flutter 混合开发获取 BinaryMessenger 报错 ( FlutterActivityAndFragmentDelegate.getFlutterEngine() )(代码片段