'微易微信支付',
'payId' => '商户号',
'payKey'=> '商户密钥',
);
$config = array(
'payId' => array(
'INPUT_TYPE' => '0',
), //商户编号
'payKey' => array(
'INPUT_TYPE' => '0',
), //商户私钥
);
/* 模块的基本信息 */
if (isset($read_modules) && $read_modules == true)
{
$module['class_name'] = 'Vyiwx';
/* 名称 */
$module['name'] = $payment_lang['name'];
/* 支付方式:1:在线支付;0:线下支付 2:仅wap支付 3:仅app支付 4:兼容wap和app*/
$module['online_pay'] = '4';
/* 配送 */
$module['config'] = $config;
$module['lang'] = $payment_lang;
$module['reg_url'] = 'http://pay.vyipay.cn/';
return $module;
}
// 支付模型
require_once(APP_ROOT_PATH.'system/libs/payment.php');
class Vyiwx_payment implements payment {
public function get_payment_code($payment_notice_id)
{
$pay = array();
$pay['is_wap'] = 1;//
$pay['class_name'] = "Vyiwx";
$pay['is_without'] = 1;//跳转外部浏览器
$pay['url'] = SITE_DOMAIN . APP_ROOT . '/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Vyiwx¬ice_id=' . $payment_notice_id;
$pay['sdk_code'] = array("pay_sdk_type" => "yjwap", "config" =>
array(
"url" => SITE_DOMAIN . APP_ROOT . '/mapi/index.php?ctl=pay&act=get_display_code&pay_code=Vyiwx¬ice_id=' . $payment_notice_id,
"is_wap" => 1
)
);
return $pay;
}
public function response($request)
{
$payment = $GLOBALS['db']->getRow("select id,config from ".DB_PREFIX."payment where class_name='Vyiwx'");
$config = unserialize($payment['config']);
$result = $this->get_md5($request,$config);
if($result['status']){
$payment_notice_sn = $request['out_trade_no'];
$outer_notice_sn = $request['trade_no'];
$payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where notice_sn = '".$payment_notice_sn."'");
$user_diamonds = $GLOBALS['db']->getOne("select diamonds from ".DB_PREFIX."user where id = '".$payment_notice['user_id']."'");
require_once APP_ROOT_PATH."system/libs/cart.php";
$rs = payment_paid($payment_notice['notice_sn'],$outer_notice_sn);
if($rs['status']==1)
{
echo '
付款成功!当前余额:'.$user_diamonds.'
';
exit;
}
else
{
echo '回调失败!关闭当前页面
';
exit;
}
} else{
echo ''.$request['msg'].'请关闭当前页面,返回APP查看
';
exit;
}
}
public function notify($request)
{
$payment = $GLOBALS['db']->getRow("select id,config from ".DB_PREFIX."payment where class_name='Vyiwx'");
$config = unserialize($payment['config']);
$result = $this->get_md5($request,$config);
if($result['status']){
$payment_notice_sn = $request['out_trade_no'];
$outer_notice_sn = $request['trade_no'];
$payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where notice_sn = '".$payment_notice_sn."'");
require_once APP_ROOT_PATH."system/libs/cart.php";
$rs = payment_paid($payment_notice['notice_sn'],$outer_notice_sn);
if($rs['status']==1)
{
echo 'SUCCESS';
}
else
{
echo 'FAIL';
}
}else
{
echo 'FAIL';
}
}
function get_display_code(){
}
public function display_code($payment_notice_id)
{
$payment_notice = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."payment_notice where id = ".$payment_notice_id);
$money = round($payment_notice['money'],2);
$payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where id=".intval($payment_notice['payment_id']));
$config = unserialize($payment_info['config']);
$order_sn = $payment_notice['notice_sn'];
$m_config = load_auto_cache("m_config");
$title_name = $m_config['ticket_name'];
if($title_name=='')
$title_name = '虚拟印币';
if(empty($title_name))
{
$title_name = "充值".round($payment_notice['money'],2)."元";
}
$Request = array();
//系统生成订单号
$Request['out_trade_no'] = $order_sn;
//商户编号
$Request['pid'] = $config['payId'];
//订单标题
$Request['name'] = $title_name;
//交易金额(单位分)
$Request['money'] = $money;
$url = $this->get_url($Request);
header('Location:'.$url);
}
function get_url($Request){
//支付方式
$type = "wxpay";
//异步通知地址
$notify_url ='http://live.huangjiaxiuchang.com/callback/payment/vyiwx_notify.php';
//客户端同步跳转通知地址
$return_url ='http://live.huangjiaxiuchang.com/callback/payment/vyiwx_response.php';
$url = "http://pay.vyipay.cn/wqpay.php?type=".$type."&pid=".$Request['pid']."&out_trade_no=".$Request['out_trade_no']."&name=".$Request['name']."&money=".$Request['money']."¬ify_url=".$notify_url."&return_url=".$return_url;
return $url;
}
function get_md5($request,$config){
$result = array('status'=>0,'error'=>'');
$id = $config['payId'];
$key = $config['payKey'];
$pid = $request['pid'];
//支付成功后返回的订单编号
$out_trade_no = $request['out_trade_no'];
//支付成功后返回的支付状态
$trade_status = $request['trade_status'];
//支付成功后返回的签名
$sign = $request['sign'];
if($request) {
if($trade_status=='SUCCESS') {
$md5 = md5($id . $out_trade_no . $trade_status . $key);
if ($sign == $md5) {
$result['status'] = 1;
} else {
$result['error'] = '签名错误';
}
}else{
$result['error'] = '支付失败,支付状态:'.$trade_status;
}
}else{
$result['error']= '无接收参数';
}
return $result;
}
}
?>