内容简介:微信支付问题总结【原创】
下图是在微信公众平台配置信息
(支付授权目录要写支付页面的路由,支付页面的左斜杠支付页面结束的路由)
(文件放在web下)
在PayController.php写入要操作的对象,以及调用回调函数,该页面有两个action
<?php /** * Created by PhpStorm. * User: zmit * Date: 5/24/17 * Time: 6:52 PM */ namespace BaseBundle\Controller; use BaseBundle\Controller\BaseController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; class PayController extends BaseController { /** * WX——jaApipay * * @param $info * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function wxPayJsApiAction($info) { // $info = id-1-key_word $info = explode('-', $info); if(count($info) >= 4){ return $this->setError('数据格式不正确'); } $conn = $this->get('database_connection'); if($info[2] == 3){//收藏视频 $order_info = $conn->fetchAssoc("SELECT id, price, type_id FROM video WHERE id = ?", array($info[0])); if(empty($order_info)){ return $this->setError('订单号不存在'); } $attach = 1; $amount = round($order_info['price'],2)*100; //拼接数字 用户id,会员类型id/或者视频id,时长,支付方式/视频收入类型, 支付类型4,当前时间 $order_number = $info[1].'-'.$info[0].'-'.$info[0].'-2-3-'.date('YmdHis'); $go_url = $this->generateUrl('user_video', array('video_type_id' => $order_info['type_id'], 'video_id' => $order_info['id'])); }elseif($info[1] == 4){//升级vip $order_info = $conn->fetchAssoc("SELECT u.id, u.vip_type, u.vip_end_date, vp.keep, vp.price, vp.sale_price FROM user u LEFT JOIN vip_type vp ON u.vip_type = vp.id WHERE u.id = ?", array($info[0])); if(empty($order_info)){ return $this->setError('订单号不存在'); } if ($order_info['sale_price'] > 0) { $vip_price = $order_info['sale_price']; } else { $vip_price = $order_info['price']; } $vip_end_date = $order_info['vip_end_date']; $keep = $order_info['keep']; if( $vip_end_date == "0000-00-00 00:00:00" || $vip_end_date ==''){ $vip_end_date = date('Y-m-d H:i:s'); } if(strtotime($vip_end_date) >= time()){ $vip_end_date = $vip_end_date ; }else{ $vip_end_date = date('Y-m-d H:i:s'); } $vip_end_date = date('Y-m-d H:i:s',strtotime("$vip_end_date +$keep month")); $attach = $vip_end_date; $amount = round($vip_price,2)*100; //拼接数字 用户id,会员类型id/或者视频,时长,支付方式/视频收入类型, 支付类型4,当前时间 $order_number = $order_info['id'].'-'.$order_info['vip_type'].'-'.$order_info['keep'].'-1-4-'.date('YmdHis'); $type_id = 1; $go_url = $this->generateUrl('user_personal_vip_success'); }else{ return $this->showErrorWeb('来源不正确'); } //执行统一下单方法 ini_set('date.timezone','Asia/Shanghai'); require_once (dirname(dirname(__FILE__)) . "/wxJsSweep/example/config.php");//导入自己写入的config文件(便于引用) //初始化日志 $logHandler= new \CLogFileHandler(dirname(dirname(__FILE__)) ."/wxJsSweep/logs/".date('Y-m-d').'.log'); $log = \Log::Init($logHandler, 15); //①、获取用户openid $tools = new \JsApiPay(); $openId = $tools->GetOpenid($this->getUrlCurrent()); //②、统一下单 $request = $this->get('request'); $input = new \WxPayUnifiedOrder(); $input->SetBody("梦航教育视频网站-付款"); $input->SetOut_trade_no($order_number); $input->SetAttach($attach);//附加数据 $input->SetTotal_fee($amount); $input->SetTime_start(date('YmdHis', time())); $input->SetTime_expire(date('YmdHis', time() + 600)); $input->SetNotify_url($request->getSchemeAndHttpHost() . $this->generateUrl('public_pay_wxPayJsApiNotify')); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $order = \WxPayApi::unifiedOrder($input); if($order['return_code'] == 'SUCCESS' AND $order['result_code'] == 'SUCCESS') { $data = array( 'info' => $tools->GetJsApiParameters($order), 'go_url' => $go_url ); return $this->render('BaseBundle:Default:pay.html.twig',array('data' => $data)); }else{ if(isset($order['err_code_des'])){ return $this->showErrorWeb($order['err_code_des']); }else{ return $this->showErrorWeb($order['return_msg']); } } } /** * WX——jaApipay-回调 * * @return JsonResponse */ public function wxPayJsApiNotifyAction() { require_once dirname(dirname(__FILE__)) . "/wxJsSweep/example/notify.php";//导入回调文件 //实例化回调 \Log::DEBUG("begin notify"); $notify = new \PayNotifyCallBack(); $notify->Handle(false); $callback = $notify->GetValues(); if($callback['return_code'] == 'SUCCESS') { $order_no = $callback['out_trade_no'];//得到之前存入的订单号 $info = explode('-', $order_no); $user_id = $info[0]; $video_or_vip = $info[1]; $keep = $info[2]; $pay_or_type = $info[3]; $attach = $callback['attach'];//得到之前到期时间 $amount = $callback['total_fee']/100; $payment_no = $callback['transaction_id']; //内部代码 $conn = $this->get('database_connection'); if($info[4] == 1){ $conn->insert('finance', array('user_id' => $user_id, 'type_id' => $pay_or_type, 'source' => $video_or_vip, 'payment_no' => $payment_no, 'add_date' => date('Y-m-d H:i:s'), 'amount' => $amount)); }elseif($info[4] == 2){ $conn->insert('finance', array('user_id' => $user_id, 'type_id' => $pay_or_type, 'source' => $video_or_vip, 'payment_no' => $payment_no, 'add_date' => date('Y-m-d H:i:s'), 'amount' => $amount)); }elseif($info[4] == 3){ $conn->insert('finance', array('user_id' => $user_id, 'type_id' => $pay_or_type, 'source' => $video_or_vip, 'payment_no' => $payment_no, 'add_date' => date('Y-m-d H:i:s'), 'amount' => $amount)); }elseif($info[4] == 4) { $conn->update('user', array('vip_end_date' => $attach), array('id' => $user_id)); $conn->insert('vip_record', array('user_id' => $user_id, 'vip_type_id' => $video_or_vip, 'vip_price' => $amount, 'vip_keep' => $keep, 'add_date' => date('Y-m-d H:i:s'), 'pay_method' => $pay_or_type)); $conn->insert('finance', array('user_id' => $user_id, 'type_id' => $pay_or_type, 'source' => $video_or_vip, 'payment_no' => $payment_no, 'add_date' => date('Y-m-d H:i:s'), 'amount' => $amount)); } } return new JsonResponse(); } }
在实际需要支付的时候,调用函数:
$pay = (int)$vip_type."-".(int)$user_id."-3"; return $this->redirect($this->generateUrl('public_pay_wxPayJsApi', array('info' => $pay)));
出现的问题
- 配置信息填写有误,导致参数获得有误
- key
- APPID
- MCHID
- APPSERECT
- 证书替换有误
3.支付授权目录填写有误
转载时请注明出处及相应链接,本文永久地址:http://blog.it985.com/21473.html
微信打赏
支付宝打赏
感谢您对作者ada的打赏,我们会更加努力! 如果您想成为作者,请点我
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 小心!网购支付页面前缀应是https不是http!三大区别总结!
- IJPay 0.5 让支付触手可及,已完成微信支付,支付宝支付
- 支付宝支付参数获取
- PHP 支付类库 PaySDK v1.0.9 新增支付宝 APP 支付
- ThinkPHP之银联支付(网页支付)
- YunGouOS 个人支付接口 2.0.5 版本发布,个人支付宝 H5、APP 支付上线
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。