namespace action\admin;
/**
* 短信服务
*/
class messageAction extends \action
{
public function sms_service(){
//操作类型 0 充值 1开通
if(!isset($_POST['type'])) return json_encode(array('RES'=>'ERR_POST','MSG'=>'操作类型为空'));
if(empty($_POST['total_row'])) return json_encode(array('RES'=>'ERR_POST','MSG'=>'短信数量为空'));
$data = $_POST;
$data['recharge_price'] = (int)$_POST['total_row']*0.01;
$data['outTradeNo'] = A('strlib/basic/randstr',array(16,3));
$m = M();
$res = $m->ins('sms_recharge')->values($data)->exe();
$order['outTradeNo'] = $data['outTradeNo'];
$order['totalAmount'] = $data['recharge_price'];
$result = $this->qrpay($order);
$order['result'] = $result;
$order['qrcode'] = "/index.php?m=admin&c=message&a=qrcode&qrcode=".$result['qr_code'];
$order['id'] = $res;
return json_encode($order);
}
public function qrpay($data){
$result = A('pay/alipay/qrpay',array($data));
$result = json_decode(json_encode($result),true);
return $result;
}
//生成登录二维码
public function qrcode() {
if(empty($_GET['qrcode'])) return;
//引入phpqrcode库文件
include(ROOT.'cube/action/phpqrcode/phpqrcode/phpqrcode.php');
$data = $_GET['qrcode'];
// 纠错级别:L、M、Q、H
$errorCorrectionLevel = 'L';
//输入二维码到浏览器
\QRcode::png($data,false,$errorCorrectionLevel,5);
}
//轮询查询支付状态
public function paystatu(){
if(empty($_POST['outTradeNo'])) return json_encode(array('RES'=>'ERR_POST'));
if(empty($_POST['id'])) return json_encode(array('RES'=>'ERR_POST'));
$result = A('pay/alipay/notify_alipay',array($_POST['outTradeNo']));
$result = json_decode(json_encode($result),true);
if($result['msg']=='Success'){
switch ($result['trade_status']) {
case 'TRADE_SUCCESS':
$res = M()->sel('phone,recharge_price,total_row,type')->from('sms_recharge')->where("id = {$_POST['id']}")->exe();
if(!$res) return json_encode(array('RES'=>'ERRSEL','MSG'=>'记录不存在!'));
$data['domain'] = $_SERVER['HTTP_HOST'];
$data['phone'] = $res['phone'];
$data['price'] = $res['recharge_price'];
$data['number'] = $res['total_row'];
$data['type'] = $res['type'];
//总站添加充值记录表
//http://dev.fushuishop.com/index.php?m=sms&c=agencySms&a=postApplyMsg
A('sms/agencySms/postApplyMsg',array($data));
$res = M()->upd('sms_recharge')->set('pay_state=1')->where("id = {$_POST['id']}")->exe();
return empty($res)?json_encode(array('RES'=>'ERRUPD','MSG'=>'支付失败')):json_encode(array('RES'=>'SUCCESS','MSG'=>'支付成功'));
break;
case 'WAIT_BUYER_PAY':
return json_encode(array('RES'=>'WAIT_BUYER_PAY','MSG'=>'等待用户支付'));
break;
case 'TRADE_CLOSED':
return json_encode(array('RES'=>'TRADE_CLOSED','MSG'=>'交易关闭'));
break;
default:
return json_encode(array('RES'=>'ERROR','MSG'=>'支付失败!'));
break;
}
}else{
return json_encode(array('RES'=>'FAILD','MSG'=>'请求失败'));
}
}
}