作者 郭鑫

pc支付上传,接口修改调试

正在显示 46 个修改的文件 包含 3294 行增加39 行删除

要显示太多修改。

为保证性能只显示 46 of 46+ 个文件。

@@ -25,7 +25,14 @@ class CommonController extends HomeBaseController @@ -25,7 +25,14 @@ class CommonController extends HomeBaseController
25 if($this->request->param('connect')){ 25 if($this->request->param('connect')){
26 $connect = $this->request->param('connect'); 26 $connect = $this->request->param('connect');
27 }else{ 27 }else{
28 - $connect = 2; 28 + $url = explode('/',$_SERVER['PATH_INFO']);
  29 + $count_url = count($url);
  30 + $fun = $url[$count_url-1];
  31 + if($fun == 'join' || $fun == 'login' || $fun == 'upload_one' ){
  32 + $connect = 1;
  33 + }else{
  34 + $connect = 2;
  35 + }
29 } 36 }
30 if($connect == 2){ 37 if($connect == 2){
31 $where_firstMember['token'] = $this->request->param('token'); 38 $where_firstMember['token'] = $this->request->param('token');
@@ -53,6 +60,7 @@ class CommonController extends HomeBaseController @@ -53,6 +60,7 @@ class CommonController extends HomeBaseController
53 } 60 }
54 61
55 } 62 }
  63 +
56 /** 64 /**
57 * API返回信息格式函数 ;0失败,1成功,-1需要登录 65 * API返回信息格式函数 ;0失败,1成功,-1需要登录
58 * @param string $code 66 * @param string $code
@@ -136,6 +136,7 @@ class IntermediaryController extends CommonController @@ -136,6 +136,7 @@ class IntermediaryController extends CommonController
136 $this->apiResponse('0','用户信息错误'); 136 $this->apiResponse('0','用户信息错误');
137 } 137 }
138 // 查询签到信息 138 // 查询签到信息
  139 + $member['pic'] = cmf_get_image_url($member['pic']);
139 $where_checkin['agency_id'] = $member['id']; 140 $where_checkin['agency_id'] = $member['id'];
140 $tme_str = date('Y-m-d',time()); 141 $tme_str = date('Y-m-d',time());
141 $where_checkin['create_time'] = strtotime($tme_str); 142 $where_checkin['create_time'] = strtotime($tme_str);
@@ -161,12 +162,21 @@ class IntermediaryController extends CommonController @@ -161,12 +162,21 @@ class IntermediaryController extends CommonController
161 public function myIndex(Request $request){ 162 public function myIndex(Request $request){
162 $token = $request->param('token'); 163 $token = $request->param('token');
163 $member = $this->left($token); 164 $member = $this->left($token);
  165 + $quarters = explode('+',$member['quarters']);
164 $final['intermediary'] = $member; 166 $final['intermediary'] = $member;
165 $where_need['city'] = $member['city']; 167 $where_need['city'] = $member['city'];
166 $where_need['status'] = 2; 168 $where_need['status'] = 2;
167 - $where_need['quarters'] = array('like','%'.$member['quarters'].'%'); 169 + if($quarters){
  170 + foreach ($quarters as $quartersk=>$quartersv){
  171 + $quarters[$quartersk] = '%'.$quartersv.'%';
  172 + }
  173 + }
  174 + $where_need['quarters'] = array('like',$quarters,'OR');
168 $page = $request->param('page'); 175 $page = $request->param('page');
169 - $need_list = Db::name('UserNeed')->where($where_need)->field("id,city,quarters,room,floor,house_type,renovation,quotation_time,create_time,people")->limit(10)->page($page)->select()->toArray(); 176 + $need_list = Db::name('UserNeed')->where($where_need)
  177 + ->field("id,city,quarters,room,floor,house_type,renovation,quotation_time,create_time,people,pay_time")
  178 + ->limit(10)->page($page)
  179 + ->select()->toArray();
170 if($need_list){ 180 if($need_list){
171 $final['intermediary_need'] = $need_list; 181 $final['intermediary_need'] = $need_list;
172 }else{ 182 }else{
@@ -195,7 +205,7 @@ class IntermediaryController extends CommonController @@ -195,7 +205,7 @@ class IntermediaryController extends CommonController
195 $where_need['id'] = $request->param('need_id'); 205 $where_need['id'] = $request->param('need_id');
196 $where_need['status'] = 2; 206 $where_need['status'] = 2;
197 $need_list = Db::name('UserNeed')->where($where_need) 207 $need_list = Db::name('UserNeed')->where($where_need)
198 - ->field("id,user_id,city,quarters,room,floor,house_type,renovation,area,is_first,loan,contract,quotation_time,create_time,people,else") 208 + ->field("id,user_id,city,quarters,room,floor,house_type,renovation,area,is_first,loan,contract,quotation_time,create_time,people,else,pay_time")
199 ->find(); 209 ->find();
200 if($need_list){ 210 if($need_list){
201 $final['intermediary_need'] = $need_list; 211 $final['intermediary_need'] = $need_list;
@@ -428,6 +438,7 @@ class IntermediaryController extends CommonController @@ -428,6 +438,7 @@ class IntermediaryController extends CommonController
428 * @param name:company type:int require:1 default: other: desc:所属公司 438 * @param name:company type:int require:1 default: other: desc:所属公司
429 * @param name:store type:int require:1 default: other: desc:门店 439 * @param name:store type:int require:1 default: other: desc:门店
430 * @param name:quarters type:int require:1 default: other: desc:服务小区 440 * @param name:quarters type:int require:1 default: other: desc:服务小区
  441 + * @param name:pic type:varchar require:1 default: other: desc:中介头像
431 * @return data:''@ 442 * @return data:''@
432 * @data status:'状态(1->待发布,2->已发布,待报价,3->已成交,4->未交保证金,5->已过期,6->未选择中介,7->中介未确认,8->报价人数不足,9->删除)' 443 * @data status:'状态(1->待发布,2->已发布,待报价,3->已成交,4->未交保证金,5->已过期,6->未选择中介,7->中介未确认,8->报价人数不足,9->删除)'
433 */ 444 */
@@ -441,6 +452,9 @@ class IntermediaryController extends CommonController @@ -441,6 +452,9 @@ class IntermediaryController extends CommonController
441 $update_member['id'] = $member['id']; 452 $update_member['id'] = $member['id'];
442 $update_member['store'] = $data['store']; 453 $update_member['store'] = $data['store'];
443 $update_member['quarters'] = $data['quarters']; 454 $update_member['quarters'] = $data['quarters'];
  455 + if(!empty($data['pic'])){
  456 + $update_member['pic'] = $data['pic'];
  457 + }
444 $model = new MemberModel(); 458 $model = new MemberModel();
445 $member = $model->isUpdate(true)->save($update_member); 459 $member = $model->isUpdate(true)->save($update_member);
446 if(!$member){ 460 if(!$member){
@@ -452,6 +466,7 @@ class IntermediaryController extends CommonController @@ -452,6 +466,7 @@ class IntermediaryController extends CommonController
452 if(!$member){ 466 if(!$member){
453 $this->apiResponse('0','中介信息有误'); 467 $this->apiResponse('0','中介信息有误');
454 }else{ 468 }else{
  469 + $member['pic'] = cmf_get_image_url($member['pic']);
455 $this->apiResponse('1','成功',$member); 470 $this->apiResponse('1','成功',$member);
456 } 471 }
457 } 472 }
@@ -47,8 +47,8 @@ class IntermediaryneedController extends CommonController @@ -47,8 +47,8 @@ class IntermediaryneedController extends CommonController
47 */ 47 */
48 public function payMoney($housing_price){ 48 public function payMoney($housing_price){
49 $where_inteRule['status'] = 1; 49 $where_inteRule['status'] = 1;
50 - $where_inteRule['low'] = array('gt',$housing_price);  
51 - $where_inteRule['height'] = array('lt',$housing_price); 50 + $where_inteRule['low'] = array('elt',$housing_price);
  51 + $where_inteRule['height'] = array('egt',$housing_price);
52 $inte_money = Db::name('IntermediaryRule')->where($where_inteRule)->field('money')->find(); 52 $inte_money = Db::name('IntermediaryRule')->where($where_inteRule)->field('money')->find();
53 if(!$inte_money){ 53 if(!$inte_money){
54 $this->apiResponse('0','保证金获取失败'); 54 $this->apiResponse('0','保证金获取失败');
@@ -119,6 +119,7 @@ class IntermediaryneedController extends CommonController @@ -119,6 +119,7 @@ class IntermediaryneedController extends CommonController
119 */ 119 */
120 public function send(Request $request) 120 public function send(Request $request)
121 { 121 {
  122 +// header('Access-Control-Allow-Origin:*');
122 if($request->Post('token') && $request->Post('housing_price')){ 123 if($request->Post('token') && $request->Post('housing_price')){
123 // 判空,处理 124 // 判空,处理
124 $validate = Loader::validate('IntermediaryNeed'); 125 $validate = Loader::validate('IntermediaryNeed');
@@ -151,12 +151,15 @@ class UserController extends CommonController @@ -151,12 +151,15 @@ class UserController extends CommonController
151 * @param name:password type:int require:1 default: other: desc:密码 151 * @param name:password type:int require:1 default: other: desc:密码
152 * @param name:sure_password type:int require:1 default: other: desc:确认密码 152 * @param name:sure_password type:int require:1 default: other: desc:确认密码
153 * @param name:code type:int require:1 default: other: desc:验证码 153 * @param name:code type:int require:1 default: other: desc:验证码
  154 + * @param name:parent_id type:int require:1 default: other: desc:推荐人id
  155 + * @param name:parent type:int require:1 default: other: desc:推荐人手机号
154 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1 156 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
155 * @return data:'token' 157 * @return data:'token'
156 */ 158 */
157 public function join(Request $request) 159 public function join(Request $request)
158 { 160 {
159 if($request->Post() && $request->Post('name')) { 161 if($request->Post() && $request->Post('name')) {
  162 + $getParam = $request->param();
160 Db::startTrans(); 163 Db::startTrans();
161 // 验证 164 // 验证
162 $validate = Loader::validate('User'); 165 $validate = Loader::validate('User');
@@ -203,9 +206,33 @@ class UserController extends CommonController @@ -203,9 +206,33 @@ class UserController extends CommonController
203 $data['token'] = $this->md5($str); 206 $data['token'] = $this->md5($str);
204 $data['type'] = 1; 207 $data['type'] = 1;
205 $data['start'] = 50; 208 $data['start'] = 50;
  209 + if(!empty($getParam['parent_id']) || !empty($getParam['parent'])){
  210 + $data['parent_id'] = $getParam['parent_id'];
  211 + $data['parent_tel'] = $getParam['parent'];
  212 + }
  213 +
206 $add = $user->allowField(true)->save($data); 214 $add = $user->allowField(true)->save($data);
207 $uid = $user->id; 215 $uid = $user->id;
208 if($add){ 216 if($add){
  217 +// 注册成功
  218 + if(!empty($getParam['parent_id'])){
  219 + $where_parentAdd['id'] = $getParam['parent_id'];
  220 + $where_parentAdd['type'] = 2;
  221 + $add_agencyScore = $user->where($where_parentAdd)->setInc('reputation','1');
  222 + if(!$add_agencyScore){
  223 + Db::rollback();
  224 + }
  225 + }
  226 +
  227 +
  228 + $url = $_SERVER['SERVER_ADDR'].$_SERVER['REDIRECT_URL'].'?uid='.$uid;
  229 + $get_url = $this->shot($url);
  230 + $update_shot['link'] = $get_url;
  231 + $update_shot['id'] = $uid;
  232 + $result_shot = $user->isUpdate(true)->save($update_shot);
  233 + if(!$result_shot){
  234 + Db::rollback();
  235 + }
209 $startAdd['detail'] = '注册获得'; 236 $startAdd['detail'] = '注册获得';
210 $startAdd['star'] = 50; 237 $startAdd['star'] = 50;
211 $startAdd['type'] = 1; 238 $startAdd['type'] = 1;
@@ -233,8 +260,15 @@ class UserController extends CommonController @@ -233,8 +260,15 @@ class UserController extends CommonController
233 $list = Db::name('Protocol')->where($where_pro)->order("update_time desc")->field("title,content")->find(); 260 $list = Db::name('Protocol')->where($where_pro)->order("update_time desc")->field("title,content")->find();
234 $list['content'] = htmlspecialchars_decode($list['content']); 261 $list['content'] = htmlspecialchars_decode($list['content']);
235 // 推荐人(未完) 262 // 推荐人(未完)
236 -  
237 - 263 + $getdata = $this->request->param();
  264 + if(!empty($getdata['uid'])){
  265 + $where_member['id'] = $getdata['uid'];
  266 + $find_parent = Db::name('Member')->where($where_member)->field('id,tel')->find();
  267 + if($find_parent){
  268 + $list['parent'] = $find_parent['tel'];
  269 + $list['parent_id'] = $find_parent['id'];
  270 + }
  271 + }
238 if($list){ 272 if($list){
239 $this->apiResponse('1','成功',$list); 273 $this->apiResponse('1','成功',$list);
240 }else{ 274 }else{
@@ -253,6 +287,7 @@ class UserController extends CommonController @@ -253,6 +287,7 @@ class UserController extends CommonController
253 * @param name:tel type:int require:1 default: other: desc:手机号 287 * @param name:tel type:int require:1 default: other: desc:手机号
254 * @param name:password type:int require:1 default: other: desc:密码 288 * @param name:password type:int require:1 default: other: desc:密码
255 * @param name:imgCode type:int require:1 default: other: desc:验证码 289 * @param name:imgCode type:int require:1 default: other: desc:验证码
  290 + * @param name:gener type:int require:1 default: other: desc:1->用户,2->中介
256 * @param name:rand type:int require:1 default: other: desc:随机数 291 * @param name:rand type:int require:1 default: other: desc:随机数
257 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1 292 * @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
258 * @return data:''@ 293 * @return data:''@
@@ -260,7 +295,6 @@ class UserController extends CommonController @@ -260,7 +295,6 @@ class UserController extends CommonController
260 */ 295 */
261 // 登录 296 // 登录
262 public function login(Request $request){ 297 public function login(Request $request){
263 -  
264 if($request->post() && $request->Post('tel')){ 298 if($request->post() && $request->Post('tel')){
265 $getData = $request->param(); 299 $getData = $request->param();
266 // 登录验证 300 // 登录验证
@@ -291,9 +325,9 @@ class UserController extends CommonController @@ -291,9 +325,9 @@ class UserController extends CommonController
291 if($find_code['code'] != $postImg){ 325 if($find_code['code'] != $postImg){
292 $this->apiResponse('0','验证码错误1'); 326 $this->apiResponse('0','验证码错误1');
293 } 327 }
294 -// else{  
295 -// Db::name('Imgcode')->where($where_imgcode)->delete();  
296 -// } 328 + else{
  329 + Db::name('Imgcode')->where($where_imgcode)->delete();
  330 + }
297 }else{ 331 }else{
298 $this->apiResponse('0','验证码错误2'); 332 $this->apiResponse('0','验证码错误2');
299 } 333 }
@@ -301,6 +335,7 @@ class UserController extends CommonController @@ -301,6 +335,7 @@ class UserController extends CommonController
301 $memberModel = new MemberModel(); 335 $memberModel = new MemberModel();
302 $where_member['tel'] = $tel; 336 $where_member['tel'] = $tel;
303 $where_member['password'] = $this->md5($password); 337 $where_member['password'] = $this->md5($password);
  338 + $where_member['type'] = $getData['gener'];
304 $uid = Db::name('Member')->where($where_member)->field('id,token,type')->find(); 339 $uid = Db::name('Member')->where($where_member)->field('id,token,type')->find();
305 if($uid){ 340 if($uid){
306 // 登录重置token 341 // 登录重置token
@@ -816,6 +851,59 @@ class UserController extends CommonController @@ -816,6 +851,59 @@ class UserController extends CommonController
816 $this->apiResponse('1','成功',$final); 851 $this->apiResponse('1','成功',$final);
817 } 852 }
818 853
  854 + /**
  855 + * @title 用户个人中心比价详情(sure)
  856 + * @description 接口说明
  857 + * @author 开发者
  858 + * @url /api/portal/User/myNeed
  859 + * @method POST
  860 + * @param name:token type:int require:1 default: other: desc:token
  861 + * @param name:need_id type:int require:1 default: other: desc:需求id
  862 + * @return data:''@
  863 + * @data status:'状态(1->待发布,2->未交保证金,3->已发布,待报价,4->报价人数不足,5->待选择中介,6->未选择中介,7->已选择中介,待中介确认,8->中介未确认,9->删除,10->已成交,中介已确认)'
  864 + * @data comment:'剩余评价次数'
  865 + */
  866 + public function myNeedDetail(Request $request){
  867 + $token = $request->param('token');
  868 + $member = $this->myleft($token);
  869 + $data = $request->param();
  870 + $final['user'] = $member;
  871 + $where_userNeed['user_id'] = $member['id'];
  872 + $where_userNeed['id'] = $member['need_id'];
  873 + $where_userNeed['status'] = array('neq',9);
  874 + $user_need = Db::name('UserNeed')->where($where_userNeed)
  875 + ->order('create_time desc')
  876 + ->select()->toArray();
  877 + if($user_need){
  878 + foreach ($user_need as $unk=>$unv){
  879 + $where_comment['need_id'] = $unv['id'];
  880 + $where_comment['user_id'] = $unv['user_id'];
  881 + $where_comment['status'] = 1;
  882 + $comment = Db::name('Comment')->where($where_comment)->field('is_comment,create_time')->find();
  883 + if($comment){
  884 +// 判断是否超过30天
  885 + if(time() > ($comment['create_time'] + 2592000)){
  886 + $user_need[$unk]['comment'] = 0;
  887 + }else{
  888 + if($comment['is_comment'] == 1){
  889 + $user_need[$unk]['comment'] = 0;
  890 + }else{
  891 + $user_need[$unk]['comment'] = 1;
  892 + }
  893 + }
  894 + }else{
  895 + $user_need[$unk]['comment'] = 2;
  896 + }
  897 +
  898 + }
  899 + $final['user_need'] = $user_need;
  900 + }else{
  901 + $final['user_need'] = array();
  902 + }
  903 + $final['user'] = $member;
  904 + $this->apiResponse('1','成功',$final);
  905 + }
  906 +
819 907
820 /** 908 /**
821 * @title 我的比价明细(sure) 909 * @title 我的比价明细(sure)
@@ -1251,8 +1339,12 @@ class UserController extends CommonController @@ -1251,8 +1339,12 @@ class UserController extends CommonController
1251 1339
1252 1340
1253 1341
1254 -  
1255 - 1342 +// 短网址
  1343 + function shot($url){
  1344 + $jump = "http://suo.im/api.php?url=".$url;
  1345 + $shot_val = file_get_contents($jump);
  1346 + return $shot_val;
  1347 + }
1256 1348
1257 1349
1258 } 1350 }
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: 29925
  5 + * Date: 2018/6/14
  6 + * Time: 16:05
  7 + */
  8 +
  9 +namespace app\portal\controller;
  10 +
  11 +use cmf\controller\HomeBaseController;
  12 +use think\Db;
  13 +use traits\controller\Jump;
  14 +
  15 +class AlipayController extends HomeBaseController
  16 +{
  17 + public function _initialize()
  18 + {
  19 + require_once VENDOR_PATH.'alipay/config.php';
  20 + require_once VENDOR_PATH.'alipay/pagepay/service/AlipayTradeService.php';
  21 + require_once VENDOR_PATH.'alipay/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php';
  22 + $this->config = $config;
  23 + }
  24 +
  25 +
  26 + public function alipay() {
  27 + $data = $this->request->param();
  28 + $config = $this->config;
  29 + //商户订单号,商户网站订单系统中唯一订单号,必填
  30 + $out_trade_no = trim($data['order_sn']);
  31 +
  32 + //订单名称,必填
  33 + $subject = trim($data['name']);
  34 +
  35 + //付款金额,必填
  36 +// $total_amount = trim(I('get.price'));
  37 + $total_amount = trim(0.01);
  38 +
  39 + //商品描述,可空
  40 + $body = '';
  41 +
  42 + //构造参数
  43 + $payRequestBuilder = new \AlipayTradePagePayContentBuilder();
  44 + $payRequestBuilder->setBody($body);
  45 + $payRequestBuilder->setSubject($subject);
  46 + $payRequestBuilder->setTotalAmount($total_amount);
  47 + $payRequestBuilder->setOutTradeNo($out_trade_no);
  48 +
  49 + $aop = new \AlipayTradeService($config);
  50 +
  51 + /**
  52 + * pagePay 电脑网站支付请求
  53 + * @param $builder 业务参数,使用buildmodel中的对象生成。
  54 + * @param $return_url 同步跳转地址,公网可以访问
  55 + * @param $notify_url 异步通知地址,公网可以访问
  56 + * @return $response 支付宝返回的信息
  57 + */
  58 + $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);
  59 +
  60 + //输出表单
  61 + var_dump($response);
  62 + }
  63 +
  64 + // 回调
  65 + public function notify_url() {
  66 + $config = $this->config;
  67 + $arr=$_POST;
  68 + $alipaySevice = new \AlipayTradeService($config);
  69 + $alipaySevice->writeLog(var_export($_POST,true));
  70 + $result = $alipaySevice->check($arr);
  71 + if($result) {
  72 + //商户订单号
  73 +
  74 + $out_trade_no = $_POST['out_trade_no'];
  75 +
  76 + //支付宝交易号
  77 +
  78 + $trade_no = $_POST['trade_no'];
  79 +
  80 + //交易状态
  81 + $trade_status = $_POST['trade_status'];
  82 +
  83 +
  84 + if($_POST['trade_status'] == 'TRADE_FINISHED') {
  85 +
  86 + //判断该笔订单是否在商户网站中已经做过处理
  87 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
  88 + //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
  89 + //如果有做过处理,不执行商户的业务程序
  90 +
  91 + //注意:
  92 + //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
  93 + }
  94 + else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
  95 + //判断该笔订单是否在商户网站中已经做过处理
  96 + //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
  97 + //请务必判断请求时的total_amount与通知时获取的total_fee为一致的
  98 + //如果有做过处理,不执行商户的业务程序
  99 + //注意:
  100 + //付款完成后,支付宝系统发送该交易状态通知
  101 + }
  102 + }
  103 + }
  104 +
  105 + //
  106 + public function return_url() {
  107 + $config = $this->config;
  108 + $arr = $_GET;
  109 + $alipaySevice = new \AlipayTradeService($config);
  110 + $result = $alipaySevice->check($arr);
  111 +// var_dump($_GET);
  112 +// echo '<br/>';
  113 +// var_dump($result);exit;
  114 + if ($result) {
  115 + //商户订单号
  116 + $out_trade_no = htmlspecialchars($_GET['out_trade_no']);
  117 +
  118 + //支付宝交易号
  119 + $trade_no = htmlspecialchars($_GET['trade_no']);
  120 + $data = $_GET;
  121 + $where['order_sn'] = $data['out_trade_no'];
  122 + $where['price'] = $data['total_amount'];
  123 + $user_licence_model = Db::name('UserLicence');
  124 + $userLicenceInfo = $user_licence_model->where($where)->find();
  125 + $info['paytype'] = 2;
  126 + $info['pay_time'] = time();
  127 + $info['status'] = 1;
  128 + $info['transaction_id'] = $data['trade_no'];
  129 + Db::startTrans();
  130 + $results = $user_licence_model->where($where)->update($info);
  131 + if(!$results) {
  132 + Db::rollback();
  133 + } else {
  134 + Db::commit();
  135 + if($userLicenceInfo['type'] == 1) {
  136 + $this->redirect(url('user/licence/sesame'));
  137 + }
  138 + if($userLicenceInfo['type'] == 2) {
  139 + $this->redirect(url('user/licence/reputation'));
  140 + }
  141 + if($userLicenceInfo['type'] == 3) {
  142 + $this->redirect(url('user/licence/edu'));
  143 + }
  144 + }
  145 + }
  146 + }
  147 +}
@@ -83,7 +83,7 @@ class BankController extends AdminBaseController @@ -83,7 +83,7 @@ class BankController extends AdminBaseController
83 { 83 {
84 if($request->post()){ 84 if($request->post()){
85 // 添加数据 85 // 添加数据
86 - $data = $request->post(); 86 + $data = $request->param();
87 if($request->Post('id')){ 87 if($request->Post('id')){
88 // 修改 88 // 修改
89 $add['name'] = $data['name']; 89 $add['name'] = $data['name'];
@@ -13,6 +13,7 @@ namespace app\portal\controller; @@ -13,6 +13,7 @@ namespace app\portal\controller;
13 use cmf\controller\HomeBaseController; 13 use cmf\controller\HomeBaseController;
14 use think\Request; 14 use think\Request;
15 use think\Loader; 15 use think\Loader;
  16 +use cmf\lib\Upload;
16 17
17 class CommonController extends HomeBaseController 18 class CommonController extends HomeBaseController
18 { 19 {
@@ -39,4 +40,34 @@ class CommonController extends HomeBaseController @@ -39,4 +40,34 @@ class CommonController extends HomeBaseController
39 $final = sha1(md5($number)); 40 $final = sha1(md5($number));
40 return $final; 41 return $final;
41 } 42 }
  43 +
  44 +
  45 + /**
  46 + * @title 上传素材
  47 + * @description 接口说明
  48 + * @author 开发者
  49 + * @url /portal/Common/upload
  50 + * @method POST
  51 +
  52 + * @param name:file type:varchar require:1 default: other: desc:素材内容
  53 + * @param name:filetype type:varchar require:1 default: other: desc:素材类型
  54 + * @param name:app type:varchar require:1 default: other: desc:素材存储路径
  55 + *
  56 + * @return title:标题
  57 + *
  58 + */
  59 + public function upload() {
  60 + if ($this->request->isPost()) {
  61 + $uploader = new Upload();
  62 +// return ["code"=>40004, "msg"=>$this->request->param(), "data"=>[$this->request->file()]];
  63 +
  64 + $result = $uploader->upload();
  65 +
  66 + if ($result === false) {
  67 + echo json_encode(["code"=>40004, "msg"=>$uploader->getError(), "data"=>[]]);exit;
  68 + } else {
  69 + echo json_encode(["code"=>1, "msg"=>"上传成功!", "data"=>[$result]]);exit;
  70 + }
  71 + }
  72 + }
42 } 73 }
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: 29925
  5 + * Date: 2018/6/13
  6 + * Time: 17:53
  7 + */
  8 +
  9 +namespace app\portal\controller;
  10 +
  11 +use cmf\controller\HomeBaseController;
  12 +use think\Db;
  13 +
  14 +class NotifyController extends HomeBaseController
  15 +{
  16 +
  17 + // 微信支付回调
  18 + public function notify() {
  19 + require_once VENDOR_PATH."WxpayAPI/lib/WxPay.Api.php";
  20 + require_once VENDOR_PATH."WxpayAPI/lib/WxPay.Notify.php";
  21 + require_once VENDOR_PATH.'WxpayAPI/example/log.php';
  22 +
  23 + $post = $this->request->param();
  24 + if($post==null){
  25 + $post = file_get_contents("php://input");
  26 + if($post == null){
  27 + $post = $GLOBALS['HTTP_RAW_POST_DATA'];
  28 + }
  29 + }
  30 + if(!empty($post)) {
  31 + $xml = $post; //微信的回调数据
  32 + $base = new \WxPayResults(); //实例化数据对象结果类
  33 + $data = $base->FromXml($xml);
  34 + if($base->CheckSign() == true){
  35 + if ($data["return_code"] == "SUCCESS") {
  36 + $where['order_sn'] = $data['attach'];
  37 + if (!$where['order_sn']) {
  38 + $where['order_sn'] = $data['out_trade_no'];
  39 + }
  40 + $where['price'] = $data['total_fee']/100;
  41 + $user_licence_model = Db::name('UserLicence');
  42 + $info = [
  43 + 'paytype'=>1,
  44 + 'pay_time'=>time(),
  45 + 'status'=>1,
  46 + 'transaction_id'=>$data['transaction_id']
  47 + ];
  48 + $results = $user_licence_model->where($where)->update($info);
  49 + if($results) {
  50 + $this->return_success();
  51 + }
  52 + }
  53 + }
  54 + }
  55 + }
  56 +
  57 + /*
  58 + * 给微信发送确认订单金额和签名正确,SUCCESS信息
  59 + */
  60 + private function return_success(){
  61 + $return['return_code'] = 'SUCCESS';
  62 + $return['return_msg'] = 'OK';
  63 + $xml_post = '<xml>
  64 + <return_code>'.$return['return_code'].'</return_code>
  65 + <return_msg>'.$return['return_msg'].'</return_msg>
  66 + </xml>';
  67 + echo $xml_post;exit;
  68 + }
  69 +
  70 + // 查询订单是否支付完成
  71 + public function searchStatus() {
  72 + if($this->request->isAjax()) {
  73 + $data = $this->request->param();
  74 + $order_sn = $data['order_sn'];
  75 + $user_licence_model = Db::name('UserLicence');
  76 + $status = $user_licence_model->where(['order_sn'=>$order_sn])->value('status');
  77 + if($status == 1) {
  78 + return ['code'=>1,'msg'=>'支付成功'];
  79 + } else {
  80 + return ['code'=>0,'msg'=>'未支付完成'];
  81 + }
  82 + }
  83 + }
  84 +}
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: 老猫 <thinkcmf@126.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\controller;
  12 +
  13 +use app\portal\model\BankModel;
  14 +use app\portal\model\BrandModel;
  15 +use app\portal\model\CooperationModel;
  16 +use app\portal\model\ProcessModel;
  17 +use app\portal\model\RewardModel;
  18 +use cmf\controller\AdminBaseController;
  19 +use app\portal\model\PortalTagModel;
  20 +use app\portal\service\PostService;
  21 +use think\Db;
  22 +use think\Request;
  23 +use think\Loader;
  24 +
  25 +class RewardController extends AdminBaseController
  26 +{
  27 + /**
  28 + * 列表(暂无用)
  29 + * @adminMenu(
  30 + * 'name' => '文章管理',
  31 + * 'parent' => 'portal/AdminIndex/default',
  32 + * 'display'=> true,
  33 + * 'hasView'=> true,
  34 + * 'order' => 10000,
  35 + * 'icon' => '',
  36 + * 'remark' => '文章列表',
  37 + * 'param' => ''
  38 + * )
  39 + */
  40 + public function index(Request $request)
  41 + {
  42 + $where_coo['status'] = 1;
  43 +// $where_coo = array();
  44 + if($request->post()){
  45 + $search = $request->post();
  46 + if($search['start_time']){
  47 + $start = strtotime($search['start_time']);
  48 + if($search['end_time']){
  49 + $end = strtotime($search['end_time']);
  50 + }else{
  51 + $end = time();
  52 + }
  53 + $where_coo['update_time'] = array('between',"$start,$end");
  54 + $this->assign('start_time',date('Y-m-d H:i',$start));
  55 + $this->assign('end_time',date('Y-m-d H:i',$end));
  56 + }
  57 + if($search['keyword']){
  58 + $where_coo['name'] = array('like',"%".$search['keyword']."%");
  59 + $this->assign('keyword',$search['keyword']);
  60 + }
  61 + }
  62 + $coo_list = Db::name('Reward')->where($where_coo)->order(' create_time desc')->paginate();
  63 + $page = $coo_list->render();
  64 + $this->assign('page',$page);
  65 + $this->assign('list',$coo_list);
  66 + return $this->fetch();
  67 + }
  68 +
  69 +
  70 + /**
  71 + * 添加、修改
  72 + * @adminMenu(
  73 + * 'name' => '添加文章',
  74 + * 'parent' => 'index',
  75 + * 'display'=> false,
  76 + * 'hasView'=> true,
  77 + * 'order' => 10000,
  78 + * 'icon' => '',
  79 + * 'remark' => '添加文章',
  80 + * 'param' => ''
  81 + * )
  82 + */
  83 + public function add(Request $request)
  84 + {
  85 + if($request->post()){
  86 +// 添加数据
  87 + $data = $request->param();
  88 + if($request->Post('id')){
  89 +// 修改
  90 + $add = $data;
  91 + $validate = Loader::validate('Bank');
  92 + if(!$validate->scene('edit')->check($add)){
  93 + $mes = $validate->getError();
  94 + $this->error("$mes");
  95 + }
  96 + $add['id'] = $request->param('id');
  97 + $model = new RewardModel();
  98 + $final = $model->isUpdate(true)->allowField(true)->save($add);
  99 + }else{
  100 +// 添加
  101 + $add = $data;
  102 + $validate = Loader::validate('Reward');
  103 + if(!$validate->scene('add')->check($add)){
  104 + $mes = $validate->getError();
  105 + $this->error("$mes");
  106 + }
  107 + $model = new RewardModel();
  108 + $final = $model->save($add);
  109 + }
  110 + if($final){
  111 + $this->success('成功',url('index'));
  112 + }else{
  113 + $this->error('失败');
  114 + }
  115 + }else{
  116 + $where_find['id'] = $request->param('id');
  117 + $list = Db::name('Reward')->where($where_find)->find();
  118 + $this->assign('list',$list);
  119 + return $this->fetch('add');
  120 + }
  121 + }
  122 +
  123 +// 删除
  124 + public function del(Request $request){
  125 + $ids = $this->request->post();
  126 + $id = $request->param('id');
  127 + if($ids){
  128 + $add_del['id'] = array('in',$ids['ids']);
  129 + }else if($id){
  130 + $add_del['id'] = $request->param('id');
  131 + }else{
  132 + $this->error('删除失败');
  133 + }
  134 + $add_del['status'] = 9;
  135 + $model = new BankModel();
  136 + $del = $model->isUpdate(true)->allowField(true)->save($add_del);
  137 + if($del){
  138 + $this->success('删除成功',url('index'));
  139 + }else{
  140 + $this->error('删除失败');
  141 + }
  142 + }
  143 +
  144 +}
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: 老猫 <thinkcmf@126.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\controller;
  12 +
  13 +use app\portal\model\BankModel;
  14 +use app\portal\model\BrandModel;
  15 +use app\portal\model\CooperationModel;
  16 +use app\portal\model\ProcessModel;
  17 +use cmf\controller\AdminBaseController;
  18 +use app\portal\model\PortalTagModel;
  19 +use app\portal\service\PostService;
  20 +use think\Db;
  21 +use think\Request;
  22 +use think\Loader;
  23 +
  24 +class ShareController extends AdminBaseController
  25 +{
  26 + /**
  27 + * 列表(暂无用)
  28 + * @adminMenu(
  29 + * 'name' => '文章管理',
  30 + * 'parent' => 'portal/AdminIndex/default',
  31 + * 'display'=> true,
  32 + * 'hasView'=> true,
  33 + * 'order' => 10000,
  34 + * 'icon' => '',
  35 + * 'remark' => '文章列表',
  36 + * 'param' => ''
  37 + * )
  38 + */
  39 + public function index(Request $request)
  40 + {
  41 + $where_coo['status'] = 1;
  42 +// $where_coo = array();
  43 + if($request->post()){
  44 + $search = $request->post();
  45 + if($search['start_time']){
  46 + $start = strtotime($search['start_time']);
  47 + if($search['end_time']){
  48 + $end = strtotime($search['end_time']);
  49 + }else{
  50 + $end = time();
  51 + }
  52 + $where_coo['update_time'] = array('between',"$start,$end");
  53 + $this->assign('start_time',date('Y-m-d H:i',$start));
  54 + $this->assign('end_time',date('Y-m-d H:i',$end));
  55 + }
  56 + if($search['keyword']){
  57 + $where_coo['name'] = array('like',"%".$search['keyword']."%");
  58 + $this->assign('keyword',$search['keyword']);
  59 + }
  60 + }
  61 + $coo_list = Db::name('Bank')->where($where_coo)->order('score desc , create_time desc')->paginate();
  62 + $page = $coo_list->render();
  63 + $this->assign('page',$page);
  64 + $this->assign('list',$coo_list);
  65 + return $this->fetch();
  66 + }
  67 +
  68 +
  69 + /**
  70 + * 添加、修改
  71 + * @adminMenu(
  72 + * 'name' => '添加文章',
  73 + * 'parent' => 'index',
  74 + * 'display'=> false,
  75 + * 'hasView'=> true,
  76 + * 'order' => 10000,
  77 + * 'icon' => '',
  78 + * 'remark' => '添加文章',
  79 + * 'param' => ''
  80 + * )
  81 + */
  82 + public function add(Request $request)
  83 + {
  84 + if($request->post()){
  85 +// 添加数据
  86 + $data = $request->param();
  87 + if($request->Post('id')){
  88 +// 修改
  89 + $add['name'] = $data['name'];
  90 + $add['score'] = $data['score'];
  91 + $validate = Loader::validate('Bank');
  92 + if(!$validate->scene('edit')->check($add)){
  93 + $mes = $validate->getError();
  94 + $this->error("$mes");
  95 + }
  96 + $add['id'] = $request->param('id');
  97 + $model = new BankModel();
  98 + $final = $model->isUpdate(true)->allowField(true)->save($add);
  99 + }else{
  100 +// 添加
  101 + $add['name'] = $data['name'];
  102 + $add['score'] = $data['score'];
  103 + $validate = Loader::validate('Bank');
  104 + if(!$validate->scene('add')->check($add)){
  105 + $mes = $validate->getError();
  106 + $this->error("$mes");
  107 + }
  108 + $model = new BankModel();
  109 + $final = $model->save($add);
  110 + }
  111 + if($final){
  112 + $this->success('成功',url('index'));
  113 + }else{
  114 + $this->error('失败');
  115 + }
  116 + }else{
  117 + $where_find['id'] = $request->param('id');
  118 + $list = Db::name('Bank')->where($where_find)->find();
  119 + $this->assign('list',$list);
  120 + return $this->fetch('add');
  121 + }
  122 + }
  123 +
  124 +// 删除
  125 + public function del(Request $request){
  126 + $ids = $this->request->post();
  127 + $id = $request->param('id');
  128 + if($ids){
  129 + $add_del['id'] = array('in',$ids['ids']);
  130 + }else if($id){
  131 + $add_del['id'] = $request->param('id');
  132 + }else{
  133 + $this->error('删除失败');
  134 + }
  135 + $add_del['status'] = 9;
  136 + $model = new BankModel();
  137 + $del = $model->isUpdate(true)->allowField(true)->save($add_del);
  138 + if($del){
  139 + $this->success('删除成功',url('index'));
  140 + }else{
  141 + $this->error('删除失败');
  142 + }
  143 + }
  144 +
  145 +}
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: 老猫 <thinkcmf@126.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\model;
  12 +
  13 +use app\admin\model\RouteModel;
  14 +use think\Model;
  15 +
  16 +class RewardModel extends Model
  17 +{
  18 + protected $autoWriteTimestamp = true;
  19 +
  20 +}
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +----------------------------------------------------------------------
  9 +// | Author: 小夏 < 449134904@qq.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace app\portal\validate;
  12 +
  13 +use think\Validate;
  14 +
  15 +class RewardValidate extends Validate
  16 +{
  17 + protected $rule = [
  18 + 'number' => 'require',
  19 + ];
  20 + protected $message = [
  21 + 'number.require' => '金额不为空!',
  22 + ];
  23 +
  24 + protected $scene = [
  25 +
  26 + ];
  27 +
  28 +}
@@ -13,7 +13,7 @@ return [ @@ -13,7 +13,7 @@ return [
13 // 用户名 13 // 用户名
14 'username' => 'root', 14 'username' => 'root',
15 // 密码 15 // 密码
16 - 'password' => '', 16 + 'password' => 'root',
17 // 端口 17 // 端口
18 'hostport' => '3306', 18 'hostport' => '3306',
19 // 数据库编码默认采用utf8 19 // 数据库编码默认采用utf8
@@ -162,6 +162,8 @@ return array ( @@ -162,6 +162,8 @@ return array (
162 'PORTAL_NEED_USER' => '需求管理', 162 'PORTAL_NEED_USER' => '需求管理',
163 'PORTAL_NEW_INDEX' => '最新成交公布', 163 'PORTAL_NEW_INDEX' => '最新成交公布',
164 'PORTAL_PROCESS_INDEX' => '交易流程', 164 'PORTAL_PROCESS_INDEX' => '交易流程',
  165 + 'PORTAL_REWARD_INDEX' => '信誉奖励设置',
  166 + 'PORTAL_SHARE_DEFAULT' => '分享内容管理',
165 'PORTAL_USERNEED_DEFAULT' => '发布需求管理', 167 'PORTAL_USERNEED_DEFAULT' => '发布需求管理',
166 'PORTAL_USERNEED_INDEX' => '保证金内容管理', 168 'PORTAL_USERNEED_INDEX' => '保证金内容管理',
167 'USER_ADMINASSET_DELETE' => '删除文件', 169 'USER_ADMINASSET_DELETE' => '删除文件',
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <li><a href="{:url('Bank/index')}">银行列表</a></li> 11 <li><a href="{:url('Bank/index')}">银行列表</a></li>
12 <li class="active"><a href="{:url('Bank/add')}">添加银行</a></li> 12 <li class="active"><a href="{:url('Bank/add')}">添加银行</a></li>
13 </ul> 13 </ul>
14 - <form action="{:url('Bank/add')}" method="post" class="form-horizontal js-ajax-form margin-top-20"> 14 + <form action="{:url('Bank/add')}" method="post" class="form-horizontal js-ajax-form margin-top-20" enctype="multipart/form-data" >
15 <div class="row"> 15 <div class="row">
16 <div class="col-md-9"> 16 <div class="col-md-9">
17 <table class="table table-bordered"> 17 <table class="table table-bordered">
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 value="{$list['id']}"/> 19 value="{$list['id']}"/>
20 <tr> 20 <tr>
21 <th width="15%">银行名称</th> 21 <th width="15%">银行名称</th>
22 - <td><input class="form-control" type="text" name="name" 22 + <td><input class="form-control" type="text" name="name11"
23 value="{$list['name']}" placeholder="请输入银行名称"/> 23 value="{$list['name']}" placeholder="请输入银行名称"/>
24 24
25 </td> 25 </td>
@@ -66,27 +66,6 @@ @@ -66,27 +66,6 @@
66 66
67 }); 67 });
68 68
69 - // function doSelectCategory() {  
70 - // var selectedCategoriesId = $('#js-categories-id-input').val();  
71 - // openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {  
72 - // area: ['700px', '400px'],  
73 - // btn: ['确定', '取消'],  
74 - // yes: function (index, layero) {  
75 - // //do something  
76 - //  
77 - // var iframeWin = window[layero.find('iframe')[0]['name']];  
78 - // var selectedCategories = iframeWin.confirm();  
79 - // if (selectedCategories.selectedCategoriesId.length == 0) {  
80 - // layer.msg('请选择分类');  
81 - // return;  
82 - // }  
83 - // $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));  
84 - // $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));  
85 - // //console.log(layer.getFrameIndex(index));  
86 - // layer.close(index); //如果设定了yes回调,需进行手工关闭  
87 - // }  
88 - // });  
89 - // }  
90 </script> 69 </script>
91 </body> 70 </body>
92 </html> 71 </html>
  1 +<include file="public@header"/>
  2 +<style type="text/css">
  3 + .pic-list li {
  4 + margin-bottom: 5px;
  5 + }
  6 +</style>
  7 +</head>
  8 +<body>
  9 +<div class="wrap js-check-wrap">
  10 + <ul class="nav nav-tabs">
  11 + <li><a href="{:url('Reward/index')}">信誉奖励列表</a></li>
  12 + <li class="active"><a href="{:url('Reward/add')}">添加信誉奖励</a></li>
  13 + </ul>
  14 + <form action="{:url('Reward/add')}" method="post" class="form-horizontal js-ajax-form margin-top-20" enctype="multipart/form-data" >
  15 + <div class="row">
  16 + <div class="col-md-9">
  17 + <table class="table table-bordered">
  18 + <input class="form-control" type="hidden" name="id"
  19 + value="{$list['id']}"/>
  20 + <tr>
  21 + <th width="15%">信誉奖励类型</th>
  22 + <td>
  23 + <select style="border: 1px solid #dce4ec;" name="type">
  24 + <option name="type[]" value="1" <eq name="list.type" value="1">selected</eq>> &nbsp;注册&nbsp;</option>
  25 + <option name="type[]" value="2" <eq name="list.type" value="2">selected</eq>> &nbsp;推荐&nbsp;</option>
  26 + <option name="type[]" value="3" <eq name="list.type" value="3">selected</eq>> &nbsp;签到&nbsp;</option>
  27 + <option name="type[]" value="4" <eq name="list.type" value="4">selected</eq>> &nbsp;成交&nbsp;</option>
  28 + </select>
  29 +
  30 + </td>
  31 + </tr>
  32 + <tr>
  33 + <th width="10%">奖励金额</th>
  34 + <td><input class="form-control" type="text" name="number"
  35 + value="{$list['number']}" placeholder="请输入奖励金额"/>
  36 +
  37 + </td>
  38 + </tr>
  39 + </table>
  40 + <div class="form-group">
  41 + <div class="col-sm-offset-2 col-sm-10">
  42 + <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
  43 + <a class="btn btn-default" href="{:url('Reward/index')}">{:lang('BACK')}</a>
  44 + </div>
  45 + </div>
  46 + </div>
  47 + </div>
  48 + </form>
  49 +</div>
  50 +<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
  51 +<script type="text/javascript">
  52 + //编辑器路径定义
  53 + var editorURL = GV.WEB_ROOT;
  54 +</script>
  55 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
  56 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
  57 +<script type="text/javascript">
  58 + $(function () {
  59 +
  60 + editorcontent = new baidu.editor.ui.Editor();
  61 + editorcontent.render('content');
  62 + try {
  63 + editorcontent.sync();
  64 + } catch (err) {
  65 + }
  66 +
  67 + $('.btn-cancel-thumbnail').click(function () {
  68 + $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
  69 + $('#thumbnail').val('');
  70 + });
  71 +
  72 + });
  73 +
  74 +</script>
  75 +</body>
  76 +</html>
  1 +<include file="public@header"/>
  2 +</head>
  3 +<body>
  4 +<div class="wrap js-check-wrap">
  5 + <ul class="nav nav-tabs">
  6 + <li class="active"><a href="javascript:;">银行列表</a></li>
  7 + <li><a href="{:url('Reward/add')}">添加银行</a></li>
  8 + </ul>
  9 + <form class="well form-inline margin-top-20" method="post" action="{:url('Reward/index')}">
  10 + <!--分类:-->
  11 + <!--<select class="form-control" name="category" style="width: 140px;">-->
  12 + <!--<option value='0'>全部</option>-->
  13 + <!--{$category_tree|default=''}-->
  14 + <!--</select> &nbsp;&nbsp;-->
  15 + 时间:
  16 + <input type="text" class="form-control js-bootstrap-datetime" name="start_time"
  17 + value="{$start_time|default=''}"
  18 + style="width: 140px;" autocomplete="off">-
  19 + <input type="text" class="form-control js-bootstrap-datetime" name="end_time"
  20 + value="{$end_time|default=''}"
  21 + style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
  22 + 关键字:
  23 + <input type="text" class="form-control" name="keyword" style="width: 200px;"
  24 + value="{$keyword|default=''}" placeholder="请输入品牌中介名称">
  25 + <input type="submit" class="btn btn-primary" value="搜索"/>
  26 + <a class="btn btn-danger" href="{:url('Reward/index')}">清空</a>
  27 + </form>
  28 + <form class="js-ajax-form" action="" method="post">
  29 + <div class="table-actions">
  30 + <!--<notempty name="category">-->
  31 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  32 + <!--data-action="{:url('AdminArticle/listOrder')}">{:lang('SORT')}-->
  33 + <!--</button>-->
  34 + <!--</notempty>-->
  35 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  36 + <!--data-action="{:url('AdminArticle/publish',array('yes'=>1))}" data-subcheck="true">发布-->
  37 + <!--</button>-->
  38 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  39 + <!--data-action="{:url('AdminArticle/publish',array('no'=>1))}" data-subcheck="true">取消发布-->
  40 + <!--</button>-->
  41 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  42 + <!--data-action="{:url('AdminArticle/top',array('yes'=>1))}" data-subcheck="true">置顶-->
  43 + <!--</button>-->
  44 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  45 + <!--data-action="{:url('AdminArticle/top',array('no'=>1))}" data-subcheck="true">取消置顶-->
  46 + <!--</button>-->
  47 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  48 + <!--data-action="{:url('AdminArticle/recommend',array('yes'=>1))}" data-subcheck="true">推荐-->
  49 + <!--</button>-->
  50 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  51 + <!--data-action="{:url('AdminArticle/recommend',array('no'=>1))}" data-subcheck="true">取消推荐-->
  52 + <!--</button>-->
  53 + <!--
  54 + <notempty name="category">
  55 + <button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button>
  56 + </notempty>
  57 + <button class="btn btn-primary btn-sm js-articles-copy" type="button">批量复制</button>
  58 + -->
  59 + <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
  60 + data-action="{:url('Reward/del')}" data-subcheck="true" data-msg="您确定删除吗?">
  61 + {:lang('DELETE')}
  62 + </button>
  63 + </div>
  64 + <table class="table table-hover table-bordered table-list">
  65 + <thead>
  66 + <tr>
  67 + <th width="15">
  68 + <label>
  69 + <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
  70 + </label>
  71 + </th>
  72 + <notempty name="category">
  73 + <th width="50">{:lang('SORT')}</th>
  74 + </notempty>
  75 + <th width="50">ID</th>
  76 + <th>类型</th>
  77 + <th>金额</th>
  78 + <!--<th>排序</th>-->
  79 + <th width="130">更新时间</th>
  80 + <th width="130">发布时间</th>
  81 + <!--<th width="70">状态</th>-->
  82 + <th width="90">操作</th>
  83 + </tr>
  84 + </thead>
  85 + <foreach name="list" item="list">
  86 + <tr>
  87 + <td>
  88 + <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
  89 + value="{$list.id}" title="ID:{$list.id}">
  90 + </td>
  91 +
  92 + <td>{$list.id}</td>
  93 + <td>
  94 + {$list.type}
  95 + </td>
  96 + <td>
  97 + {$list.number}
  98 + </td>
  99 + <td>
  100 + {:date('Y-m-d H:i',$list['update_time'])}
  101 + </td>
  102 + <td>
  103 + {:date('Y-m-d H:i',$list['create_time'])}
  104 + <!--<empty name="vo.published_time">-->
  105 + <!--未发布-->
  106 + <!--<else/>-->
  107 + <!--{:date('Y-m-d H:i',$list['published_time'])}-->
  108 + <!--</empty>-->
  109 +
  110 + </td>
  111 +
  112 + <td>
  113 + <a href="{:url('Reward/add',array('id'=>$list['id']))}">{:lang('EDIT')}</a>
  114 + <a href="{:url('Reward/del',array('id'=>$list['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
  115 + </td>
  116 + </tr>
  117 + </foreach>
  118 +
  119 + </table>
  120 +
  121 + <ul class="pagination">{$page|default=''}</ul>
  122 + </form>
  123 +</div>
  124 +<script src="__STATIC__/js/admin.js"></script>
  125 +<script>
  126 +
  127 + function reloadPage(win) {
  128 + win.location.reload();
  129 + }
  130 +
  131 + $(function () {
  132 + setCookie("refersh_time", 0);
  133 + Wind.use('ajaxForm', 'artDialog', 'iframeTools', function () {
  134 + //批量复制
  135 + $('.js-articles-copy').click(function (e) {
  136 + var ids = [];
  137 + $("input[name='ids[]']").each(function () {
  138 + if ($(this).is(':checked')) {
  139 + ids.push($(this).val());
  140 + }
  141 + });
  142 +
  143 + if (ids.length == 0) {
  144 + art.dialog.through({
  145 + id: 'error',
  146 + icon: 'error',
  147 + content: '您没有勾选信息,无法进行操作!',
  148 + cancelVal: '关闭',
  149 + cancel: true
  150 + });
  151 + return false;
  152 + }
  153 +
  154 + ids = ids.join(',');
  155 + art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=copy&ids=" + ids, {
  156 + title: "批量复制",
  157 + width: "300px"
  158 + });
  159 + });
  160 + //批量移动
  161 + $('.js-articles-move').click(function (e) {
  162 + var ids = [];
  163 + $("input[name='ids[]']").each(function () {
  164 + if ($(this).is(':checked')) {
  165 + ids.push($(this).val());
  166 + }
  167 + });
  168 +
  169 + if (ids.length == 0) {
  170 + art.dialog.through({
  171 + id: 'error',
  172 + icon: 'error',
  173 + content: '您没有勾选信息,无法进行操作!',
  174 + cancelVal: '关闭',
  175 + cancel: true
  176 + });
  177 + return false;
  178 + }
  179 +
  180 + ids = ids.join(',');
  181 + art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=move&old_term_id={$term.term_id|default=0}&ids=" + ids, {
  182 + title: "批量移动",
  183 + width: "300px"
  184 + });
  185 + });
  186 + });
  187 + });
  188 +</script>
  189 +</body>
  190 +</html>
  1 +<include file="public@header"/>
  2 +<style type="text/css">
  3 + .pic-list li {
  4 + margin-bottom: 5px;
  5 + }
  6 +</style>
  7 +</head>
  8 +<body>
  9 +<div class="wrap js-check-wrap">
  10 + <ul class="nav nav-tabs">
  11 + <li><a href="{:url('Bank/index')}">银行列表</a></li>
  12 + <li class="active"><a href="{:url('Bank/add')}">添加银行</a></li>
  13 + </ul>
  14 + <form action="{:url('Bank/add')}" method="post" class="form-horizontal js-ajax-form margin-top-20" enctype="multipart/form-data" >
  15 + <div class="row">
  16 + <div class="col-md-9">
  17 + <table class="table table-bordered">
  18 + <input class="form-control" type="hidden" name="id"
  19 + value="{$list['id']}"/>
  20 + <tr>
  21 + <th width="15%">银行名称</th>
  22 + <td><input class="form-control" type="text" name="name11"
  23 + value="{$list['name']}" placeholder="请输入银行名称"/>
  24 +
  25 + </td>
  26 + </tr>
  27 + <tr>
  28 + <th width="10%">排序</th>
  29 + <td><input class="form-control" type="text" name="score"
  30 + value="{$list['score']}" placeholder="请输入排序,数字越大越靠前"/>
  31 +
  32 + </td>
  33 + </tr>
  34 + </table>
  35 + <div class="form-group">
  36 + <div class="col-sm-offset-2 col-sm-10">
  37 + <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
  38 + <a class="btn btn-default" href="{:url('Bank/index')}">{:lang('BACK')}</a>
  39 + </div>
  40 + </div>
  41 + </div>
  42 + </div>
  43 + </form>
  44 +</div>
  45 +<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
  46 +<script type="text/javascript">
  47 + //编辑器路径定义
  48 + var editorURL = GV.WEB_ROOT;
  49 +</script>
  50 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
  51 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
  52 +<script type="text/javascript">
  53 + $(function () {
  54 +
  55 + editorcontent = new baidu.editor.ui.Editor();
  56 + editorcontent.render('content');
  57 + try {
  58 + editorcontent.sync();
  59 + } catch (err) {
  60 + }
  61 +
  62 + $('.btn-cancel-thumbnail').click(function () {
  63 + $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
  64 + $('#thumbnail').val('');
  65 + });
  66 +
  67 + });
  68 +
  69 +</script>
  70 +</body>
  71 +</html>
  1 +<include file="public@header"/>
  2 +</head>
  3 +<body>
  4 +<div class="wrap js-check-wrap">
  5 + <ul class="nav nav-tabs">
  6 + <li class="active"><a href="javascript:;">银行列表</a></li>
  7 + <li><a href="{:url('Bank/add')}">添加银行</a></li>
  8 + </ul>
  9 + <form class="well form-inline margin-top-20" method="post" action="{:url('Bank/index')}">
  10 + <!--分类:-->
  11 + <!--<select class="form-control" name="category" style="width: 140px;">-->
  12 + <!--<option value='0'>全部</option>-->
  13 + <!--{$category_tree|default=''}-->
  14 + <!--</select> &nbsp;&nbsp;-->
  15 + 时间:
  16 + <input type="text" class="form-control js-bootstrap-datetime" name="start_time"
  17 + value="{$start_time|default=''}"
  18 + style="width: 140px;" autocomplete="off">-
  19 + <input type="text" class="form-control js-bootstrap-datetime" name="end_time"
  20 + value="{$end_time|default=''}"
  21 + style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
  22 + 关键字:
  23 + <input type="text" class="form-control" name="keyword" style="width: 200px;"
  24 + value="{$keyword|default=''}" placeholder="请输入品牌中介名称">
  25 + <input type="submit" class="btn btn-primary" value="搜索"/>
  26 + <a class="btn btn-danger" href="{:url('Bank/index')}">清空</a>
  27 + </form>
  28 + <form class="js-ajax-form" action="" method="post">
  29 + <div class="table-actions">
  30 + <!--<notempty name="category">-->
  31 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  32 + <!--data-action="{:url('AdminArticle/listOrder')}">{:lang('SORT')}-->
  33 + <!--</button>-->
  34 + <!--</notempty>-->
  35 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  36 + <!--data-action="{:url('AdminArticle/publish',array('yes'=>1))}" data-subcheck="true">发布-->
  37 + <!--</button>-->
  38 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  39 + <!--data-action="{:url('AdminArticle/publish',array('no'=>1))}" data-subcheck="true">取消发布-->
  40 + <!--</button>-->
  41 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  42 + <!--data-action="{:url('AdminArticle/top',array('yes'=>1))}" data-subcheck="true">置顶-->
  43 + <!--</button>-->
  44 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  45 + <!--data-action="{:url('AdminArticle/top',array('no'=>1))}" data-subcheck="true">取消置顶-->
  46 + <!--</button>-->
  47 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  48 + <!--data-action="{:url('AdminArticle/recommend',array('yes'=>1))}" data-subcheck="true">推荐-->
  49 + <!--</button>-->
  50 + <!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
  51 + <!--data-action="{:url('AdminArticle/recommend',array('no'=>1))}" data-subcheck="true">取消推荐-->
  52 + <!--</button>-->
  53 + <!--
  54 + <notempty name="category">
  55 + <button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button>
  56 + </notempty>
  57 + <button class="btn btn-primary btn-sm js-articles-copy" type="button">批量复制</button>
  58 + -->
  59 + <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
  60 + data-action="{:url('Bank/del')}" data-subcheck="true" data-msg="您确定删除吗?">
  61 + {:lang('DELETE')}
  62 + </button>
  63 + </div>
  64 + <table class="table table-hover table-bordered table-list">
  65 + <thead>
  66 + <tr>
  67 + <th width="15">
  68 + <label>
  69 + <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
  70 + </label>
  71 + </th>
  72 + <notempty name="category">
  73 + <th width="50">{:lang('SORT')}</th>
  74 + </notempty>
  75 + <th width="50">ID</th>
  76 + <th>品牌中介名</th>
  77 + <th>排序</th>
  78 + <!--<th>排序</th>-->
  79 + <th width="130">更新时间</th>
  80 + <th width="130">发布时间</th>
  81 + <!--<th width="70">状态</th>-->
  82 + <th width="90">操作</th>
  83 + </tr>
  84 + </thead>
  85 + <foreach name="list" item="list">
  86 + <tr>
  87 + <td>
  88 + <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
  89 + value="{$list.id}" title="ID:{$list.id}">
  90 + </td>
  91 +
  92 + <td>{$list.id}</td>
  93 + <td>
  94 + {$list.name}
  95 + </td>
  96 + <td>
  97 + {$list.score}
  98 + </td>
  99 + <td>
  100 + {:date('Y-m-d H:i',$list['update_time'])}
  101 + </td>
  102 + <td>
  103 + {:date('Y-m-d H:i',$list['create_time'])}
  104 + <!--<empty name="vo.published_time">-->
  105 + <!--未发布-->
  106 + <!--<else/>-->
  107 + <!--{:date('Y-m-d H:i',$list['published_time'])}-->
  108 + <!--</empty>-->
  109 +
  110 + </td>
  111 +
  112 + <td>
  113 + <a href="{:url('Bank/add',array('id'=>$list['id']))}">{:lang('EDIT')}</a>
  114 + <a href="{:url('Bank/del',array('id'=>$list['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
  115 + </td>
  116 + </tr>
  117 + </foreach>
  118 +
  119 + </table>
  120 +
  121 + <ul class="pagination">{$page|default=''}</ul>
  122 + </form>
  123 +</div>
  124 +<script src="__STATIC__/js/admin.js"></script>
  125 +<script>
  126 +
  127 + function reloadPage(win) {
  128 + win.location.reload();
  129 + }
  130 +
  131 + $(function () {
  132 + setCookie("refersh_time", 0);
  133 + Wind.use('ajaxForm', 'artDialog', 'iframeTools', function () {
  134 + //批量复制
  135 + $('.js-articles-copy').click(function (e) {
  136 + var ids = [];
  137 + $("input[name='ids[]']").each(function () {
  138 + if ($(this).is(':checked')) {
  139 + ids.push($(this).val());
  140 + }
  141 + });
  142 +
  143 + if (ids.length == 0) {
  144 + art.dialog.through({
  145 + id: 'error',
  146 + icon: 'error',
  147 + content: '您没有勾选信息,无法进行操作!',
  148 + cancelVal: '关闭',
  149 + cancel: true
  150 + });
  151 + return false;
  152 + }
  153 +
  154 + ids = ids.join(',');
  155 + art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=copy&ids=" + ids, {
  156 + title: "批量复制",
  157 + width: "300px"
  158 + });
  159 + });
  160 + //批量移动
  161 + $('.js-articles-move').click(function (e) {
  162 + var ids = [];
  163 + $("input[name='ids[]']").each(function () {
  164 + if ($(this).is(':checked')) {
  165 + ids.push($(this).val());
  166 + }
  167 + });
  168 +
  169 + if (ids.length == 0) {
  170 + art.dialog.through({
  171 + id: 'error',
  172 + icon: 'error',
  173 + content: '您没有勾选信息,无法进行操作!',
  174 + cancelVal: '关闭',
  175 + cancel: true
  176 + });
  177 + return false;
  178 + }
  179 +
  180 + ids = ids.join(',');
  181 + art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=move&old_term_id={$term.term_id|default=0}&ids=" + ids, {
  182 + title: "批量移动",
  183 + width: "300px"
  184 + });
  185 + });
  186 + });
  187 + });
  188 +</script>
  189 +</body>
  190 +</html>
@@ -71,6 +71,56 @@ class HomeBaseController extends BaseController @@ -71,6 +71,56 @@ class HomeBaseController extends BaseController
71 } 71 }
72 72
73 /** 73 /**
  74 + * 生成二维码
  75 + * $param url 地址
  76 + */
  77 + public function createQRcode($url) {
  78 + require VENDOR_PATH.'WxpayAPI/example/phpqrcode/phpqrcode.php';
  79 + $QRcode = new \QRcode();
  80 + $errorCorrectionLevel = 'L'; //容错级别
  81 + $matrixPointSize = 5; //生成图片大小
  82 + //生成二维码图片
  83 + $data = './upload/';
  84 + $flodername = 'qrcode/' . date("Ymd", time());
  85 + $png = uniqid() . '.png';
  86 + $filename = $data.$flodername . '/' . $png;
  87 + if (!file_exists($data.$flodername)) {
  88 + mkdir($data.$flodername, 0777, true);
  89 + }
  90 + $QRcode->png($url, $filename, $errorCorrectionLevel, $matrixPointSize);
  91 + return $flodername . '/' . $png;
  92 + }
  93 +
  94 +
  95 + /**
  96 + * 微信支付(pc扫码支付)
  97 + */
  98 + protected function wxpay($orderInfo,$sort) {
  99 + require_once VENDOR_PATH."WxpayAPI/lib/WxPay.Api.php";
  100 + require_once VENDOR_PATH."WxpayAPI/example/WxPay.JsApiPay.php";
  101 + require_once VENDOR_PATH."WxpayAPI/example/WxPay.NativePay.php";
  102 + require_once VENDOR_PATH."WxpayAPI/lib/WxPay.Notify.php";
  103 + require_once VENDOR_PATH.'WxpayAPI/example/log.php';
  104 + $notify = new \NativePay();
  105 + $input = new \WxPayUnifiedOrder();
  106 + $input->SetBody($sort);
  107 + $input->SetAttach($orderInfo['order_sn']);
  108 + $input->SetOut_trade_no(\WxPayConfig::MCHID.date("YmdHis"));
  109 + $input->SetTotal_fee($orderInfo['price']*100);//$orderInfo['price_count']*100
  110 + $input->SetTime_start(date("YmdHis"));
  111 + $input->SetTime_expire(date("YmdHis", time() + 600));
  112 + $input->SetGoods_tag("test");
  113 +// $input->SetNotify_url('http://ccimc.com/simplewind/Core/Library/Vendor/WxpayAPI/example/notify.php');
  114 + $input->SetNotify_url(url('portal/notify/notify','',true,true));
  115 + $input->SetTrade_type("NATIVE");
  116 + $input->SetProduct_id('');
  117 + $result = $notify->GetPayUrl($input);
  118 + return $result;
  119 + }
  120 +
  121 +
  122 +
  123 + /**
74 * 加载模板输出 124 * 加载模板输出
75 * @access protected 125 * @access protected
76 * @param string $template 模板文件名 126 * @param string $template 模板文件名
  1 +-----BEGIN CERTIFICATE-----
  2 +MIIEYzCCA8ygAwIBAgIEAQgxjjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC
  3 +Q04xEjAQBgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNV
  4 +BAoTB1RlbmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEf
  5 +MB0GCSqGSIb3DQEJARYQbW1wYXltY2hAdGVuY2VudDAeFw0xNzA1MTUxNDQwMDRa
  6 +Fw0yNzA1MTMxNDQwMDRaMIGSMQswCQYDVQQGEwJDTjESMBAGA1UECBMJR3Vhbmdk
  7 +b25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UEChMHVGVuY2VudDEOMAwGA1UE
  8 +CxMFTU1QYXkxJzAlBgNVBAMUHuWkqea0peaWueebruenkeaKgOaciemZkOWFrOWP
  9 +uDERMA8GA1UEBBMIMjY5NzcwNTMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
  10 +AoIBAQC90K1g8cq3GvkERn22Sw02x68qCpD+q5owh5fcEdjTL6zwtAC80Jx8Yd0G
  11 +3DBpeCkefHEmq73pPQRt3pXD+AGT/ffsSFQtDU8p/CC0eqzfU5PM14z1xZjdrMiM
  12 +xQZSqwg6WRIQjdYp1ypTlgx+3IP2cVqa6v1t7MfRpZ1SeqMYdAIFGELwGxwxJjFe
  13 +ArCodzDzvYs/t6KKyb4VjhvmNIxwG+GwK1OZHy+Y5PVBeGQdJGXMzNSM5O4Ur2bc
  14 +qLN3K5VTLRHFqJNohd1dTDOcAyZfYOtcp2b/rQ2d+jrGu9CrHdh79I3/Srdmjq9L
  15 +iqgV9gOQNKu0Q91VVZd8YvVjqMpVAgMBAAGjggFGMIIBQjAJBgNVHRMEAjAAMCwG
  16 +CWCGSAGG+EIBDQQfFh0iQ0VTLUNBIEdlbmVyYXRlIENlcnRpZmljYXRlIjAdBgNV
  17 +HQ4EFgQU5jvXZ+kAyNtyc7hfuQsgPlfaXikwgb8GA1UdIwSBtzCBtIAUPgUm9iJi
  18 +tBVbiM1kfrDUYqflhnShgZCkgY0wgYoxCzAJBgNVBAYTAkNOMRIwEAYDVQQIEwlH
  19 +dWFuZ2RvbmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdUZW5jZW50MQww
  20 +CgYDVQQLEwNXWEcxEzARBgNVBAMTCk1tcGF5bWNoQ0ExHzAdBgkqhkiG9w0BCQEW
  21 +EG1tcGF5bWNoQHRlbmNlbnSCCQC7VJcrvADoVzAOBgNVHQ8BAf8EBAMCBsAwFgYD
  22 +VR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEARNKry3veIem6
  23 +7sK620ApJdWYkuHeJcmT8AKN/LbV/bLPe6CY+fgtd0wSSaR3b1CUuDPQFEoPQS2p
  24 +S3tNHpqZmB5rkHUfMxBMib6+tCLvsxyKmHXWiaZOFiumwwuLn2OAjKkm5DkBD3sV
  25 +CHtQu3Kqt6NID7/Y1By1dccOgZGuNIE=
  26 +-----END CERTIFICATE-----
  1 +-----BEGIN PRIVATE KEY-----
  2 +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC90K1g8cq3GvkE
  3 +Rn22Sw02x68qCpD+q5owh5fcEdjTL6zwtAC80Jx8Yd0G3DBpeCkefHEmq73pPQRt
  4 +3pXD+AGT/ffsSFQtDU8p/CC0eqzfU5PM14z1xZjdrMiMxQZSqwg6WRIQjdYp1ypT
  5 +lgx+3IP2cVqa6v1t7MfRpZ1SeqMYdAIFGELwGxwxJjFeArCodzDzvYs/t6KKyb4V
  6 +jhvmNIxwG+GwK1OZHy+Y5PVBeGQdJGXMzNSM5O4Ur2bcqLN3K5VTLRHFqJNohd1d
  7 +TDOcAyZfYOtcp2b/rQ2d+jrGu9CrHdh79I3/Srdmjq9LiqgV9gOQNKu0Q91VVZd8
  8 +YvVjqMpVAgMBAAECggEAMm+ugiH9YWYTYOVyJewPWMz6aEtid6kVUWvWGC3N1V/H
  9 +rjXGNGWiDxLZ7ia33m6FTop2bnYYAk+qS59nYCkYEkDbjbcyVr5AmMFb11j5cmX8
  10 +0eM8m1mj4tM0fuMjaPf1ObvNJwTpMTjxEEDAlTz2+5bnIl7qdDkEZ1qAURgxGh/T
  11 +oqtji7+8trEUeXzi8mRk2s++kDEe1cMN8hHqGwecJGAA8dg3WWilNSSGV9Y42mZX
  12 +YSBsMkwWpgK/yIrSkhR3D4rCB0BTajtCvEL37vNYhtYAbNxKZ638YnbJAlz+/Bv0
  13 +yRI8WTfrzE1Aviom/+RGDkBQW7loVObUux8Kq89qQQKBgQDuGEYdIfxdtis+b2ZK
  14 +bTC0TUsf0gPC7icgilLhGzIGEWxZzopybENBOle2UuORkuDffpWjjtheD+D8+N/R
  15 +sC4H4UoqzSy6Y6MiJH2L0zA7odWvmZsdNei9pup8fQZnwxCGxfObmd3Dm+Sv7fVD
  16 +gU6eZ+aapLpS8+Oaxq7vxLq8rQKBgQDMFvA47cvTHTEthWvZ0ejakhebcTxILjRO
  17 +Bnws30WSoWzbnpNd34DlBdJRXIj+Kbh80Q5GNbPBeIo7+Y/5MnezFC+eDfEXdb+k
  18 +Fv/t/yswNrrJaAKRLP3ZtIInHgSKBp2rBJvQU+X0WNW7VrhGiBSnAmabqM+4rwTi
  19 +EpYYGheRSQKBgH6jdpeEPiDyBeo9gmDP1vnvqqeQIuQJm9IZAKAuwNqtZb4Wt1jI
  20 +8LS+/WxChjwlrWnygFDwZ3EQbRDgptt3I+SZFcPSQZoZ6Oj+E7DNcXgmSewOfYx5
  21 +4gMNxubT8RY7kIy+uSXoHyYtwuM4ZB21p0Vl6igSue/pPQRT7TQmpVQ5AoGATUhu
  22 +ZRBfO611PuikI5KiW4ow2FLz4d1lPxqjkRZnMRRhtXSCF20YUSF4OAkTczN3QgSk
  23 +JCAX1q5/oiBpzZK30x9UvMRIxHp5PHjdJ1GWGCbRao0xU6o24mbBVnC+hUnmEKmp
  24 +GyV6EaJGJS+8jjDfqTJ2ioFNT4EvFzC0l6HhxMkCgYAJml7eXlmPc8pcL30kP3Vf
  25 +UF6lvCOH5ioPMj8IX0fuUjMU3S9mvGjKJIR3R+J8U821KSyiQKl26tJmVfjW1/KI
  26 +nY5J6ucwM26/y46M97JhW9+m8j+BPvdSai1SxQm0Jne5/1ZDp2QLMWiqsnE0VPWm
  27 +IQjv5v1VQVYZgFnLR7h3Qw==
  28 +-----END PRIVATE KEY-----
  1 +SDK
  2 +体验地址
  3 +http://paysdk.weixin.qq.com/
  4 +
  5 +快速搭建指南
  6 +①、安装配置nginx+phpfpm+php
  7 +②、建SDK解压到网站根目录
  8 +③、修改lib/WxPay.Config.php为自己申请的商户号的信息(配置详见说明)
  9 +⑤、下载证书替换cert下的文件
  10 +⑥、搭建完成
  11 +
  12 +SDK目录结构
  13 +|-- cert
  14 +| |-- apiclient_cert.pem
  15 +| `-- apiclient_key.pem
  16 +|-- index.php
  17 +|-- lib
  18 +| |-- WxPay.Api.php
  19 +| |-- WxPay.Config.php
  20 +| |-- WxPay.Data.php
  21 +| |-- WxPay.Exception.php
  22 +| `-- WxPay.Notify.php
  23 +|-- logs
  24 +| |-- 2015-03-06.log
  25 +| `-- 2015-03-11.log
  26 +`-- example
  27 + |-- WxPay.JsApiPay.php
  28 + |-- WxPay.MicroPay.php
  29 + |-- WxPay.NativePay.php
  30 + |-- download.php
  31 + |-- micropay.php
  32 + |-- native.php
  33 + |-- native_notify.php
  34 + |-- notify.php
  35 + |-- orderquery.php
  36 + |-- qrcode.php
  37 + |-- refund.php
  38 + |-- refundquery.php
  39 + |-- jsapi.php
  40 + |-- log.php
  41 + `-- phpqrcode
  42 +
  43 +目录功能简介
  44 +lib
  45 +API接口封装代码
  46 +WxPay.Api.php 包括所有微信支付API接口的封装
  47 +WxPay.Config.php 商户配置
  48 +WxPay.Data.php 输入参数封装
  49 +WxPay.Exception.php 异常类
  50 +WxPay.Notify.php 回调通知基类
  51 +
  52 +cert
  53 +证书存放路径,证书可以登录商户平台https://pay.weixin.qq.com/index.php/account/api_cert下载
  54 +
  55 +example
  56 +样例程序代码路径
  57 +
  58 +example/phpqrcode
  59 +开源二维码php代码
  60 +
  61 +logs
  62 +日志文件
  63 +
  64 +※配置指南
  65 +MCHID = '1225312702';
  66 +这里填开户邮件中的商户号
  67 +
  68 +APPID = 'wx426b3015555a46be';
  69 +这里填开户邮件中的(公众账号APPID或者应用APPID)
  70 +
  71 +KEY = 'e10adc3949ba59abbe56e057f20f883e'
  72 +这里请使用商户平台登录账户和密码登录http://pay.weixin.qq.com 平台设置的“API密钥”,为了安全,请设置为32字符串。
  73 +
  74 +APPSECRET = '01c6d59a3f9024db6336662ac95c8e74'
  75 +改参数在JSAPI支付(open平台账户不能进行JSAPI支付)的时候需要用来获取用户openid,可使用APPID对应的公众平台登录http://mp.weixin.qq.com 的开发者中心获取AppSecret。
  76 +
  1 +<?php
  2 +require_once VENDOR_PATH."WxpayAPI/lib/WxPay.Api.php";
  3 +/**
  4 + *
  5 + * JSAPI支付实现类
  6 + * 该类实现了从微信公众平台获取code、通过code获取openid和access_token、
  7 + * 生成jsapi支付js接口所需的参数、生成获取共享收货地址所需的参数
  8 + *
  9 + * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发
  10 + *
  11 + * @author widy
  12 + *
  13 + */
  14 +class JsApiPay
  15 +{
  16 + /**
  17 + *
  18 + * 网页授权接口微信服务器返回的数据,返回样例如下
  19 + * {
  20 + * "access_token":"ACCESS_TOKEN",
  21 + * "expires_in":7200,
  22 + * "refresh_token":"REFRESH_TOKEN",
  23 + * "openid":"OPENID",
  24 + * "scope":"SCOPE",
  25 + * "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
  26 + * }
  27 + * 其中access_token可用于获取共享收货地址
  28 + * openid是微信支付jsapi支付接口必须的参数
  29 + * @var array
  30 + */
  31 + public $data = null;
  32 +
  33 + /**
  34 + *
  35 + * 通过跳转获取用户的openid,跳转流程如下:
  36 + * 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
  37 + * 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
  38 + *
  39 + * @return 用户的openid
  40 + */
  41 + public function GetOpenid()
  42 + {
  43 + //通过code获得openid
  44 + if (!isset($_GET['code'])){
  45 + //触发微信返回code码
  46 + $baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  47 + $url = $this->__CreateOauthUrlForCode($baseUrl);
  48 + Header("Location: $url");
  49 + exit();
  50 + } else {
  51 + //获取code码,以获取openid
  52 + $code = $_GET['code'];
  53 + $openid = $this->getOpenidFromMp($code);
  54 + return $openid;
  55 + }
  56 + }
  57 +
  58 + /**
  59 + *
  60 + * 获取jsapi支付的参数
  61 + * @param array $UnifiedOrderResult 统一支付接口返回的数据
  62 + * @throws WxPayException
  63 + *
  64 + * @return json数据,可直接填入js函数作为参数
  65 + */
  66 + public function GetJsApiParameters($UnifiedOrderResult)
  67 + {
  68 + if(!array_key_exists("appid", $UnifiedOrderResult)
  69 + || !array_key_exists("prepay_id", $UnifiedOrderResult)
  70 + || $UnifiedOrderResult['prepay_id'] == "")
  71 + {
  72 + throw new WxPayException("参数错误");
  73 + }
  74 + $jsapi = new WxPayJsApiPay();
  75 + $jsapi->SetAppid($UnifiedOrderResult["appid"]);
  76 + $timeStamp = time();
  77 + $jsapi->SetTimeStamp("$timeStamp");
  78 + $jsapi->SetNonceStr(WxPayApi::getNonceStr());
  79 + $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
  80 + $jsapi->SetSignType("MD5");
  81 + $jsapi->SetPaySign($jsapi->MakeSign());
  82 + $parameters = json_encode($jsapi->GetValues());
  83 + return $parameters;
  84 + }
  85 +
  86 + /**
  87 + *
  88 + * 通过code从工作平台获取openid机器access_token
  89 + * @param string $code 微信跳转回来带上的code
  90 + *
  91 + * @return openid
  92 + */
  93 + public function GetOpenidFromMp($code)
  94 + {
  95 + $url = $this->__CreateOauthUrlForOpenid($code);
  96 + //初始化curl
  97 + $ch = curl_init();
  98 + //设置超时
  99 + curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
  100 + curl_setopt($ch, CURLOPT_URL, $url);
  101 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
  102 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
  103 + curl_setopt($ch, CURLOPT_HEADER, FALSE);
  104 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  105 + if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
  106 + && WxPayConfig::CURL_PROXY_PORT != 0){
  107 + curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
  108 + curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
  109 + }
  110 + //运行curl,结果以jason形式返回
  111 + $res = curl_exec($ch);
  112 + curl_close($ch);
  113 + //取出openid
  114 + $data = json_decode($res,true);
  115 + $this->data = $data;
  116 + $openid = $data['openid'];
  117 + return $openid;
  118 + }
  119 +
  120 + /**
  121 + *
  122 + * 拼接签名字符串
  123 + * @param array $urlObj
  124 + *
  125 + * @return 返回已经拼接好的字符串
  126 + */
  127 + private function ToUrlParams($urlObj)
  128 + {
  129 + $buff = "";
  130 + foreach ($urlObj as $k => $v)
  131 + {
  132 + if($k != "sign"){
  133 + $buff .= $k . "=" . $v . "&";
  134 + }
  135 + }
  136 +
  137 + $buff = trim($buff, "&");
  138 + return $buff;
  139 + }
  140 +
  141 + /**
  142 + *
  143 + * 获取地址js参数
  144 + *
  145 + * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用
  146 + */
  147 + public function GetEditAddressParameters()
  148 + {
  149 + $getData = $this->data;
  150 + $data = array();
  151 + $data["appid"] = WxPayConfig::APPID;
  152 + $data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  153 + $time = time();
  154 + $data["timestamp"] = "$time";
  155 + $data["noncestr"] = "1234568";
  156 + $data["accesstoken"] = $getData["access_token"];
  157 + ksort($data);
  158 + $params = $this->ToUrlParams($data);
  159 + $addrSign = sha1($params);
  160 +
  161 + $afterData = array(
  162 + "addrSign" => $addrSign,
  163 + "signType" => "sha1",
  164 + "scope" => "jsapi_address",
  165 + "appId" => WxPayConfig::APPID,
  166 + "timeStamp" => $data["timestamp"],
  167 + "nonceStr" => $data["noncestr"]
  168 + );
  169 + $parameters = json_encode($afterData);
  170 + return $parameters;
  171 + }
  172 +
  173 + /**
  174 + *
  175 + * 构造获取code的url连接
  176 + * @param string $redirectUrl 微信服务器回跳的url,需要url编码
  177 + *
  178 + * @return 返回构造好的url
  179 + */
  180 + private function __CreateOauthUrlForCode($redirectUrl)
  181 + {
  182 + $urlObj["appid"] = WxPayConfig::APPID;
  183 + $urlObj["redirect_uri"] = "$redirectUrl";
  184 + $urlObj["response_type"] = "code";
  185 + $urlObj["scope"] = "snsapi_base";
  186 + $urlObj["state"] = "STATE"."#wechat_redirect";
  187 + $bizString = $this->ToUrlParams($urlObj);
  188 + return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
  189 + }
  190 +
  191 + /**
  192 + *
  193 + * 构造获取open和access_toke的url地址
  194 + * @param string $code,微信跳转带回的code
  195 + *
  196 + * @return 请求的url
  197 + */
  198 + private function __CreateOauthUrlForOpenid($code)
  199 + {
  200 + $urlObj["appid"] = WxPayConfig::APPID;
  201 + $urlObj["secret"] = WxPayConfig::APPSECRET;
  202 + $urlObj["code"] = $code;
  203 + $urlObj["grant_type"] = "authorization_code";
  204 + $bizString = $this->ToUrlParams($urlObj);
  205 + return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
  206 + }
  207 +}
  1 +<?php
  2 +require_once "../lib/WxPay.Api.php";
  3 +/**
  4 + *
  5 + * 刷卡支付实现类
  6 + * 该类实现了一个刷卡支付的流程,流程如下:
  7 + * 1、提交刷卡支付
  8 + * 2、根据返回结果决定是否需要查询订单,如果查询之后订单还未变则需要返回查询(一般反复查10次)
  9 + * 3、如果反复查询10订单依然不变,则发起撤销订单
  10 + * 4、撤销订单需要循环撤销,一直撤销成功为止(注意循环次数,建议10次)
  11 + *
  12 + * 该类是微信支付提供的样例程序,商户可根据自己的需求修改,或者使用lib中的api自行开发,为了防止
  13 + * 查询时hold住后台php进程,商户查询和撤销逻辑可在前端调用
  14 + *
  15 + * @author widy
  16 + *
  17 + */
  18 +class MicroPay
  19 +{
  20 + /**
  21 + *
  22 + * 提交刷卡支付,并且确认结果,接口比较慢
  23 + * @param WxPayMicroPay $microPayInput
  24 + * @throws WxpayException
  25 + * @return 返回查询接口的结果
  26 + */
  27 + public function pay($microPayInput)
  28 + {
  29 + //①、提交被扫支付
  30 + $result = WxPayApi::micropay($microPayInput, 5);
  31 + //如果返回成功
  32 + if(!array_key_exists("return_code", $result)
  33 + || !array_key_exists("out_trade_no", $result)
  34 + || !array_key_exists("result_code", $result))
  35 + {
  36 + echo "接口调用失败,请确认是否输入是否有误!";
  37 + throw new WxPayException("接口调用失败!");
  38 + }
  39 +
  40 + //签名验证
  41 + $out_trade_no = $microPayInput->GetOut_trade_no();
  42 +
  43 + //②、接口调用成功,明确返回调用失败
  44 + if($result["return_code"] == "SUCCESS" &&
  45 + $result["result_code"] == "FAIL" &&
  46 + $result["err_code"] != "USERPAYING" &&
  47 + $result["err_code"] != "SYSTEMERROR")
  48 + {
  49 + return false;
  50 + }
  51 +
  52 + //③、确认支付是否成功
  53 + $queryTimes = 10;
  54 + while($queryTimes > 0)
  55 + {
  56 + $succResult = 0;
  57 + $queryResult = $this->query($out_trade_no, $succResult);
  58 + //如果需要等待1s后继续
  59 + if($succResult == 2){
  60 + sleep(2);
  61 + continue;
  62 + } else if($succResult == 1){//查询成功
  63 + return $queryResult;
  64 + } else {//订单交易失败
  65 + return false;
  66 + }
  67 + }
  68 +
  69 + //④、次确认失败,则撤销订单
  70 + if(!$this->cancel($out_trade_no))
  71 + {
  72 + throw new WxpayException("撤销单失败!");
  73 + }
  74 +
  75 + return false;
  76 + }
  77 +
  78 + /**
  79 + *
  80 + * 查询订单情况
  81 + * @param string $out_trade_no 商户订单号
  82 + * @param int $succCode 查询订单结果
  83 + * @return 0 订单不成功,1表示订单成功,2表示继续等待
  84 + */
  85 + public function query($out_trade_no, &$succCode)
  86 + {
  87 + $queryOrderInput = new WxPayOrderQuery();
  88 + $queryOrderInput->SetOut_trade_no($out_trade_no);
  89 + $result = WxPayApi::orderQuery($queryOrderInput);
  90 +
  91 + if($result["return_code"] == "SUCCESS"
  92 + && $result["result_code"] == "SUCCESS")
  93 + {
  94 + //支付成功
  95 + if($result["trade_state"] == "SUCCESS"){
  96 + $succCode = 1;
  97 + return $result;
  98 + }
  99 + //用户支付中
  100 + else if($result["trade_state"] == "USERPAYING"){
  101 + $succCode = 2;
  102 + return false;
  103 + }
  104 + }
  105 +
  106 + //如果返回错误码为“此交易订单号不存在”则直接认定失败
  107 + if($result["err_code"] == "ORDERNOTEXIST")
  108 + {
  109 + $succCode = 0;
  110 + } else{
  111 + //如果是系统错误,则后续继续
  112 + $succCode = 2;
  113 + }
  114 + return false;
  115 + }
  116 +
  117 + /**
  118 + *
  119 + * 撤销订单,如果失败会重复调用10次
  120 + * @param string $out_trade_no
  121 + * @param 调用深度 $depth
  122 + */
  123 + public function cancel($out_trade_no, $depth = 0)
  124 + {
  125 + if($depth > 10){
  126 + return false;
  127 + }
  128 +
  129 + $clostOrder = new WxPayReverse();
  130 + $clostOrder->SetOut_trade_no($out_trade_no);
  131 + $result = WxPayApi::reverse($clostOrder);
  132 +
  133 + //接口调用失败
  134 + if($result["return_code"] != "SUCCESS"){
  135 + return false;
  136 + }
  137 +
  138 + //如果结果为success且不需要重新调用撤销,则表示撤销成功
  139 + if($result["result_code"] != "SUCCESS"
  140 + && $result["recall"] == "N"){
  141 + return true;
  142 + } else if($result["recall"] == "Y") {
  143 + return $this->cancel($out_trade_no, ++$depth);
  144 + }
  145 + return false;
  146 + }
  147 +}
  1 +<?php
  2 +//require_once "../lib/WxPay.Api.php";
  3 +
  4 +/**
  5 + *
  6 + * 刷卡支付实现类
  7 + * @author widyhu
  8 + *
  9 + */
  10 +class NativePay
  11 +{
  12 + /**
  13 + *
  14 + * 生成扫描支付URL,模式一
  15 + * @param BizPayUrlInput $bizUrlInfo
  16 + */
  17 + public function GetPrePayUrl($productId)
  18 + {
  19 + $biz = new WxPayBizPayUrl();
  20 + $biz->SetProduct_id($productId);
  21 + $values = WxpayApi::bizpayurl($biz);
  22 + $url = "weixin://wxpay/bizpayurl?" . $this->ToUrlParams($values);
  23 + return $url;
  24 + }
  25 +
  26 + /**
  27 + *
  28 + * 参数数组转换为url参数
  29 + * @param array $urlObj
  30 + */
  31 + private function ToUrlParams($urlObj)
  32 + {
  33 + $buff = "";
  34 + foreach ($urlObj as $k => $v)
  35 + {
  36 + $buff .= $k . "=" . $v . "&";
  37 + }
  38 +
  39 + $buff = trim($buff, "&");
  40 + return $buff;
  41 + }
  42 +
  43 + /**
  44 + *
  45 + * 生成直接支付url,支付url有效期为2小时,模式二
  46 + * @param UnifiedOrderInput $input
  47 + */
  48 + public function GetPayUrl($input)
  49 + {
  50 + if($input->GetTrade_type() == "NATIVE")
  51 + {
  52 + $result = WxPayApi::unifiedOrder($input);
  53 + return $result;
  54 + }
  55 + }
  56 +}
  1 +<?php
  2 +require_once "../lib/WxPay.Api.php";
  3 +//require_once "../lib/WxPay.MicroPay.php";
  4 +
  5 +
  6 +if(isset($_REQUEST["bill_date"]) && $_REQUEST["bill_date"] != ""){
  7 + $bill_date = $_REQUEST["bill_date"];
  8 + $bill_type = $_REQUEST["bill_type"];
  9 + $input = new WxPayDownloadBill();
  10 + $input->SetBill_date($bill_date);
  11 + $input->SetBill_type($bill_type);
  12 + $file = WxPayApi::downloadBill($input);
  13 + echo $file;
  14 + //TODO 对账单文件处理
  15 + exit(0);
  16 +}
  17 +?>
  18 +<html>
  19 +<head>
  20 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  21 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  22 + <title>微信支付样例-查退款单</title>
  23 +</head>
  24 +<body>
  25 + <form action="#" method="post">
  26 + <div style="margin-left:2%;">对账日期:</div><br/>
  27 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="bill_date" /><br /><br />
  28 + <div style="margin-left:2%;">账单类型:</div><br/>
  29 + <select style="width:96%;height:35px;margin-left:2%;" name="bill_type">
  30 + <option value ="ALL">所有订单信息</option>
  31 + <option value ="SUCCESS">成功支付的订单</option>
  32 + <option value="REFUND">退款订单</option>
  33 + <option value="REVOKED">撤销的订单</option>
  34 + </select><br /><br />
  35 + <div align="center">
  36 + <input type="submit" value="下载订单" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
  37 + </div>
  38 + </form>
  39 +</body>
  40 +</html>
  1 +<?php
  2 +ini_set('date.timezone','Asia/Shanghai');
  3 +//error_reporting(E_ERROR);
  4 +require_once "../lib/WxPay.Api.php";
  5 +//require_once "WxPay.JsApiPay.php";
  6 +require_once 'log.php';
  7 +//echo 111;exit;
  8 +//初始化日志
  9 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  10 +$log = Log::Init($logHandler, 15);
  11 +
  12 +//打印输出数组信息
  13 +function printf_info($data)
  14 +{
  15 + foreach($data as $key=>$value){
  16 + echo "<font color='#00ff55;'>$key</font> : $value <br/>";
  17 + }
  18 +}
  19 +
  20 +//①、获取用户openid
  21 +$tools = new JsApiPay();
  22 +$openId = $tools->GetOpenid();
  23 +
  24 +//②、统一下单
  25 +$input = new WxPayUnifiedOrder();
  26 +$input->SetBody("test");
  27 +$input->SetAttach("test");
  28 +$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  29 +$input->SetTotal_fee("1");
  30 +$input->SetTime_start(date("YmdHis"));
  31 +$input->SetTime_expire(date("YmdHis", time() + 600));
  32 +$input->SetGoods_tag("test");
  33 +$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
  34 +$input->SetTrade_type("JSAPI");
  35 +$input->SetOpenid($openId);
  36 +$order = WxPayApi::unifiedOrder($input);
  37 +echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
  38 +printf_info($order);
  39 +$jsApiParameters = $tools->GetJsApiParameters($order);
  40 +
  41 +//获取共享收货地址js函数参数
  42 +$editAddress = $tools->GetEditAddressParameters();
  43 +
  44 +//③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
  45 +/**
  46 + * 注意:
  47 + * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
  48 + * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
  49 + * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
  50 + */
  51 +?>
  52 +
  53 +<html>
  54 +<head>
  55 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  56 + <meta name="viewport" content="width=device-width, initial-scale=1"/>
  57 + <title>微信支付样例-支付</title>
  58 + <script type="text/javascript">
  59 + //调用微信JS api 支付
  60 + function jsApiCall()
  61 + {
  62 + WeixinJSBridge.invoke(
  63 + 'getBrandWCPayRequest',
  64 + <?php echo $jsApiParameters; ?>,
  65 + function(res){
  66 + WeixinJSBridge.log(res.err_msg);
  67 + alert(res.err_code+res.err_desc+res.err_msg);
  68 + }
  69 + );
  70 + }
  71 +
  72 + function callpay()
  73 + {
  74 + if (typeof WeixinJSBridge == "undefined"){
  75 + if( document.addEventListener ){
  76 + document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  77 + }else if (document.attachEvent){
  78 + document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  79 + document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  80 + }
  81 + }else{
  82 + jsApiCall();
  83 + }
  84 + }
  85 + </script>
  86 + <script type="text/javascript">
  87 + //获取共享地址
  88 + function editAddress()
  89 + {
  90 + WeixinJSBridge.invoke(
  91 + 'editAddress',
  92 + <?php echo $editAddress; ?>,
  93 + function(res){
  94 + var value1 = res.proviceFirstStageName;
  95 + var value2 = res.addressCitySecondStageName;
  96 + var value3 = res.addressCountiesThirdStageName;
  97 + var value4 = res.addressDetailInfo;
  98 + var tel = res.telNumber;
  99 +
  100 + alert(value1 + value2 + value3 + value4 + ":" + tel);
  101 + }
  102 + );
  103 + }
  104 +
  105 + window.onload = function(){
  106 + if (typeof WeixinJSBridge == "undefined"){
  107 + if( document.addEventListener ){
  108 + document.addEventListener('WeixinJSBridgeReady', editAddress, false);
  109 + }else if (document.attachEvent){
  110 + document.attachEvent('WeixinJSBridgeReady', editAddress);
  111 + document.attachEvent('onWeixinJSBridgeReady', editAddress);
  112 + }
  113 + }else{
  114 + editAddress();
  115 + }
  116 + };
  117 +
  118 + </script>
  119 +</head>
  120 +<body>
  121 + <br/>
  122 + <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span></b></font><br/><br/>
  123 + <div align="center">
  124 + <button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" >立即支付</button>
  125 + </div>
  126 +</body>
  127 +</html>
  1 +<?php
  2 +//以下为日志
  3 +
  4 +interface ILogHandler
  5 +{
  6 + public function write($msg);
  7 +
  8 +}
  9 +
  10 +class CLogFileHandler implements ILogHandler
  11 +{
  12 + private $handle = null;
  13 +
  14 + public function __construct($file = '')
  15 + {
  16 + $this->handle = fopen($file,'a');
  17 + }
  18 +
  19 + public function write($msg)
  20 + {
  21 + fwrite($this->handle, $msg, 4096);
  22 + }
  23 +
  24 + public function __destruct()
  25 + {
  26 + fclose($this->handle);
  27 + }
  28 +}
  29 +
  30 +class Log
  31 +{
  32 + private $handler = null;
  33 + private $level = 15;
  34 +
  35 + private static $instance = null;
  36 +
  37 + private function __construct(){}
  38 +
  39 + private function __clone(){}
  40 +
  41 + public static function Init($handler = null,$level = 15)
  42 + {
  43 + if(!self::$instance instanceof self)
  44 + {
  45 + self::$instance = new self();
  46 + self::$instance->__setHandle($handler);
  47 + self::$instance->__setLevel($level);
  48 + }
  49 + return self::$instance;
  50 + }
  51 +
  52 +
  53 + private function __setHandle($handler){
  54 + $this->handler = $handler;
  55 + }
  56 +
  57 + private function __setLevel($level)
  58 + {
  59 + $this->level = $level;
  60 + }
  61 +
  62 + public static function DEBUG($msg)
  63 + {
  64 + self::$instance->write(1, $msg);
  65 + }
  66 +
  67 + public static function WARN($msg)
  68 + {
  69 + self::$instance->write(4, $msg);
  70 + }
  71 +
  72 + public static function ERROR($msg)
  73 + {
  74 + $debugInfo = debug_backtrace();
  75 + $stack = "[";
  76 + foreach($debugInfo as $key => $val){
  77 + if(array_key_exists("file", $val)){
  78 + $stack .= ",file:" . $val["file"];
  79 + }
  80 + if(array_key_exists("line", $val)){
  81 + $stack .= ",line:" . $val["line"];
  82 + }
  83 + if(array_key_exists("function", $val)){
  84 + $stack .= ",function:" . $val["function"];
  85 + }
  86 + }
  87 + $stack .= "]";
  88 + self::$instance->write(8, $stack . $msg);
  89 + }
  90 +
  91 + public static function INFO($msg)
  92 + {
  93 + self::$instance->write(2, $msg);
  94 + }
  95 +
  96 + private function getLevelStr($level)
  97 + {
  98 + switch ($level)
  99 + {
  100 + case 1:
  101 + return 'debug';
  102 + break;
  103 + case 2:
  104 + return 'info';
  105 + break;
  106 + case 4:
  107 + return 'warn';
  108 + break;
  109 + case 8:
  110 + return 'error';
  111 + break;
  112 + default:
  113 +
  114 + }
  115 + }
  116 +
  117 + protected function write($level,$msg)
  118 + {
  119 + if(($level & $this->level) == $level )
  120 + {
  121 + $msg = '['.date('Y-m-d H:i:s').']['.$this->getLevelStr($level).'] '.$msg."\n";
  122 + $this->handler->write($msg);
  123 + }
  124 + }
  125 +}
  1 +<html>
  2 +<head>
  3 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  5 + <title>微信支付样例-查退款单</title>
  6 +</head>
  7 +<?php
  8 +require_once "../lib/WxPay.Api.php";
  9 +require_once "WxPay.MicroPay.php";
  10 +require_once 'log.php';
  11 +
  12 +//初始化日志
  13 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  14 +$log = Log::Init($logHandler, 15);
  15 +
  16 +//打印输出数组信息
  17 +function printf_info($data)
  18 +{
  19 + foreach($data as $key=>$value){
  20 + echo "<font color='#00ff55;'>$key</font> : $value <br/>";
  21 + }
  22 +}
  23 +
  24 +if(isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != ""){
  25 + $auth_code = $_REQUEST["auth_code"];
  26 + $input = new WxPayMicroPay();
  27 + $input->SetAuth_code($auth_code);
  28 + $input->SetBody("刷卡测试样例-支付");
  29 + $input->SetTotal_fee("1");
  30 + $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  31 +
  32 + $microPay = new MicroPay();
  33 + printf_info($microPay->pay($input));
  34 +}
  35 +
  36 +/**
  37 + * 注意:
  38 + * 1、提交被扫之后,返回系统繁忙、用户输入密码等错误信息时需要循环查单以确定是否支付成功
  39 + * 2、多次(一半10次)确认都未明确成功时需要调用撤单接口撤单,防止用户重复支付
  40 + */
  41 +
  42 +?>
  43 +<body>
  44 + <form action="#" method="post">
  45 + <div style="margin-left:2%;">商品描述:</div><br/>
  46 + <input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="刷卡测试样例-支付" name="auth_code" /><br /><br />
  47 + <div style="margin-left:2%;">支付金额:</div><br/>
  48 + <input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="1分" name="auth_code" /><br /><br />
  49 + <div style="margin-left:2%;">授权码:</div><br/>
  50 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="auth_code" /><br /><br />
  51 + <div align="center">
  52 + <input type="submit" value="提交刷卡" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
  53 + </div>
  54 + </form>
  55 +</body>
  56 +</html>
  1 +<?php
  2 +ini_set('date.timezone','Asia/Shanghai');
  3 +//error_reporting(E_ERROR);
  4 +
  5 +require_once "../lib/WxPay.Api.php";
  6 +require_once "WxPay.NativePay.php";
  7 +require_once 'log.php';
  8 +
  9 +//模式一
  10 +/**
  11 + * 流程:
  12 + * 1、组装包含支付信息的url,生成二维码
  13 + * 2、用户扫描二维码,进行支付
  14 + * 3、确定支付之后,微信服务器会回调预先配置的回调地址,在【微信开放平台-微信支付-支付配置】中进行配置
  15 + * 4、在接到回调通知之后,用户进行统一下单支付,并返回支付信息以完成支付(见:native_notify.php)
  16 + * 5、支付完成之后,微信服务器会通知支付成功
  17 + * 6、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
  18 + */
  19 +$notify = new NativePay();
  20 +$url1 = $notify->GetPrePayUrl("123456789");
  21 +
  22 +//模式二
  23 +/**
  24 + * 流程:
  25 + * 1、调用统一下单,取得code_url,生成二维码
  26 + * 2、用户扫描二维码,进行支付
  27 + * 3、支付完成之后,微信服务器会通知支付成功
  28 + * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
  29 + */
  30 +$input = new WxPayUnifiedOrder();
  31 +$input->SetBody("test");
  32 +$input->SetAttach("test");
  33 +$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  34 +$input->SetTotal_fee("1");
  35 +$input->SetTime_start(date("YmdHis"));
  36 +$input->SetTime_expire(date("YmdHis", time() + 600));
  37 +$input->SetGoods_tag("test");
  38 +$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
  39 +$input->SetTrade_type("NATIVE");
  40 +$input->SetProduct_id("123456789");
  41 +$result = $notify->GetPayUrl($input);
  42 +$url2 = $result["code_url"];
  43 +?>
  44 +
  45 +<html>
  46 +<head>
  47 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  48 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  49 + <title>微信支付样例-退款</title>
  50 +</head>
  51 +<body>
  52 + <div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式一</div><br/>
  53 + <img alt="模式一扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<?php echo urlencode($url1);?>" style="width:150px;height:150px;"/>
  54 + <br/><br/><br/>
  55 + <div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div><br/>
  56 + <img alt="模式二扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<?php echo urlencode($url2);?>" style="width:150px;height:150px;"/>
  57 +
  58 +</body>
  59 +</html>
  1 +<?php
  2 +ini_set('date.timezone','Asia/Shanghai');
  3 +error_reporting(E_ERROR);
  4 +
  5 +require_once "../lib/WxPay.Api.php";
  6 +require_once '../lib/WxPay.Notify.php';
  7 +require_once 'log.php';
  8 +
  9 +//初始化日志
  10 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  11 +$log = Log::Init($logHandler, 15);
  12 +
  13 +class NativeNotifyCallBack extends WxPayNotify
  14 +{
  15 + public function unifiedorder($openId, $product_id)
  16 + {
  17 + //统一下单
  18 + $input = new WxPayUnifiedOrder();
  19 + $input->SetBody("test");
  20 + $input->SetAttach("test");
  21 + $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
  22 + $input->SetTotal_fee("1");
  23 + $input->SetTime_start(date("YmdHis"));
  24 + $input->SetTime_expire(date("YmdHis", time() + 600));
  25 + $input->SetGoods_tag("test");
  26 + $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
  27 + $input->SetTrade_type("NATIVE");
  28 + $input->SetOpenid($openId);
  29 + $input->SetProduct_id($product_id);
  30 + $result = WxPayApi::unifiedOrder($input);
  31 + Log::DEBUG("unifiedorder:" . json_encode($result));
  32 + return $result;
  33 + }
  34 +
  35 + public function NotifyProcess($data, &$msg)
  36 + {
  37 + //echo "处理回调";
  38 + Log::DEBUG("call back:" . json_encode($data));
  39 +
  40 + if(!array_key_exists("openid", $data) ||
  41 + !array_key_exists("product_id", $data))
  42 + {
  43 + $msg = "回调数据异常";
  44 + return false;
  45 + }
  46 +
  47 + $openid = $data["openid"];
  48 + $product_id = $data["product_id"];
  49 +
  50 + //统一下单
  51 + $result = $this->unifiedorder($openid, $product_id);
  52 + if(!array_key_exists("appid", $result) ||
  53 + !array_key_exists("mch_id", $result) ||
  54 + !array_key_exists("prepay_id", $result))
  55 + {
  56 + $msg = "统一下单失败";
  57 + return false;
  58 + }
  59 +
  60 + $this->SetData("appid", $result["appid"]);
  61 + $this->SetData("mch_id", $result["mch_id"]);
  62 + $this->SetData("nonce_str", WxPayApi::getNonceStr());
  63 + $this->SetData("prepay_id", $result["prepay_id"]);
  64 + $this->SetData("result_code", "SUCCESS");
  65 + $this->SetData("err_code_des", "OK");
  66 + return true;
  67 + }
  68 +}
  69 +
  70 +Log::DEBUG("begin notify!");
  71 +$notify = new NativeNotifyCallBack();
  72 +$notify->Handle(true);
  1 +<?php
  2 +ini_set('date.timezone','Asia/Shanghai');
  3 +error_reporting(E_ERROR);
  4 +
  5 +require_once "../lib/WxPay.Api.php";
  6 +require_once '../lib/WxPay.Notify.php';
  7 +require_once 'log.php';
  8 +
  9 +//初始化日志
  10 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  11 +$log = Log::Init($logHandler, 15);
  12 +
  13 +class PayNotifyCallBack extends WxPayNotify
  14 +{
  15 + //查询订单
  16 + public function Queryorder($transaction_id)
  17 + {
  18 + $input = new WxPayOrderQuery();
  19 + $input->SetTransaction_id($transaction_id);
  20 + $result = WxPayApi::orderQuery($input);
  21 + Log::DEBUG("query:" . json_encode($result));
  22 + if(array_key_exists("return_code", $result)
  23 + && array_key_exists("result_code", $result)
  24 + && $result["return_code"] == "SUCCESS"
  25 + && $result["result_code"] == "SUCCESS")
  26 + {
  27 + return true;
  28 + }
  29 + return false;
  30 + }
  31 +
  32 + //重写回调处理函数
  33 + public function NotifyProcess($data, &$msg)
  34 + {
  35 + Log::DEBUG("call back:" . json_encode($data));
  36 + $notfiyOutput = array();
  37 +
  38 + if(!array_key_exists("transaction_id", $data)){
  39 + $msg = "输入参数不正确";
  40 + return false;
  41 + }
  42 + //查询订单,判断订单真实性
  43 + if(!$this->Queryorder($data["transaction_id"])){
  44 + $msg = "订单查询失败";
  45 + return false;
  46 + }
  47 + return true;
  48 + }
  49 +}
  50 +
  51 +Log::DEBUG("begin notify");
  52 +$notify = new PayNotifyCallBack();
  53 +$notify->Handle(false);
  1 +<html>
  2 +<head>
  3 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  5 + <title>微信支付样例-订单查询</title>
  6 +</head>
  7 +<?php
  8 +ini_set('date.timezone','Asia/Shanghai');
  9 +error_reporting(E_ERROR);
  10 +require_once "../lib/WxPay.Api.php";
  11 +require_once 'log.php';
  12 +
  13 +//初始化日志
  14 +$logHandler= new CLogFileHandler("./logs/".date('Y-m-d').'.log');
  15 +$log = Log::Init($logHandler, 15);
  16 +
  17 +function printf_info($data)
  18 +{
  19 + foreach($data as $key=>$value){
  20 + echo "<font color='#f00;'>$key</font> : $value <br/>";
  21 + }
  22 +}
  23 +
  24 +
  25 +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
  26 + $transaction_id = $_REQUEST["transaction_id"];
  27 + $input = new WxPayOrderQuery();
  28 + $input->SetTransaction_id($transaction_id);
  29 + printf_info(WxPayApi::orderQuery($input));
  30 + exit();
  31 +}
  32 +
  33 +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
  34 + $out_trade_no = $_REQUEST["out_trade_no"];
  35 + $input = new WxPayOrderQuery();
  36 + $input->SetOut_trade_no($out_trade_no);
  37 + printf_info(WxPayApi::orderQuery($input));
  38 + exit();
  39 +}
  40 +?>
  41 +<body>
  42 + <form action="#" method="post">
  43 + <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/>
  44 + <div style="margin-left:2%;">微信订单号:</div><br/>
  45 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
  46 + <div style="margin-left:2%;">商户订单号:</div><br/>
  47 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
  48 + <div align="center">
  49 + <input type="submit" value="查询" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
  50 + </div>
  51 + </form>
  52 +</body>
  53 +</html>
  1 +<?php
  2 +error_reporting(E_ERROR);
  3 +require_once 'phpqrcode/phpqrcode1.php';
  4 +$url = urldecode($_GET["data"]);
  5 +QRcode::png($url);
  1 +<html>
  2 +<head>
  3 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  5 + <title>微信支付样例-退款</title>
  6 +</head>
  7 +<?php
  8 +ini_set('date.timezone','Asia/Shanghai');
  9 +error_reporting(E_ERROR);
  10 +require_once "../lib/WxPay.Api.php";
  11 +require_once 'log.php';
  12 +
  13 +//初始化日志
  14 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  15 +$log = Log::Init($logHandler, 15);
  16 +
  17 +function printf_info($data)
  18 +{
  19 + foreach($data as $key=>$value){
  20 + echo "<font color='#f00;'>$key</font> : $value <br/>";
  21 + }
  22 +}
  23 +
  24 +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
  25 + $transaction_id = $_REQUEST["transaction_id"];
  26 + $total_fee = $_REQUEST["total_fee"];
  27 + $refund_fee = $_REQUEST["refund_fee"];
  28 + $input = new WxPayRefund();
  29 + $input->SetTransaction_id($transaction_id);
  30 + $input->SetTotal_fee($total_fee);
  31 + $input->SetRefund_fee($refund_fee);
  32 + $input->SetOut_refund_no(WxPayConfig::MCHID.date("YmdHis"));
  33 + $input->SetOp_user_id(WxPayConfig::MCHID);
  34 + printf_info(WxPayApi::refund($input));
  35 + exit();
  36 +}
  37 +
  38 +//$_REQUEST["out_trade_no"]= "122531270220150304194108";
  39 +///$_REQUEST["total_fee"]= "1";
  40 +//$_REQUEST["refund_fee"] = "1";
  41 +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
  42 + $out_trade_no = $_REQUEST["out_trade_no"];
  43 + $total_fee = $_REQUEST["total_fee"];
  44 + $refund_fee = $_REQUEST["refund_fee"];
  45 + $input = new WxPayRefund();
  46 + $input->SetOut_trade_no($out_trade_no);
  47 + $input->SetTotal_fee($total_fee);
  48 + $input->SetRefund_fee($refund_fee);
  49 + $input->SetOut_refund_no(WxPayConfig::MCHID.date("YmdHis"));
  50 + $input->SetOp_user_id(WxPayConfig::MCHID);
  51 + printf_info(WxPayApi::refund($input));
  52 + exit();
  53 +}
  54 +?>
  55 +<body>
  56 + <form action="#" method="post">
  57 + <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/>
  58 + <div style="margin-left:2%;">微信订单号:</div><br/>
  59 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
  60 + <div style="margin-left:2%;">商户订单号:</div><br/>
  61 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
  62 + <div style="margin-left:2%;">订单总金额(分):</div><br/>
  63 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="total_fee" /><br /><br />
  64 + <div style="margin-left:2%;">退款金额(分):</div><br/>
  65 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_fee" /><br /><br />
  66 + <div align="center">
  67 + <input type="submit" value="提交退款" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
  68 + </div>
  69 + </form>
  70 +</body>
  71 +</html>
  1 +<html>
  2 +<head>
  3 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1" />
  5 + <title>微信支付样例-查退款单</title>
  6 +</head>
  7 +<?php
  8 +ini_set('date.timezone','Asia/Shanghai');
  9 +error_reporting(E_ERROR);
  10 +require_once "../lib/WxPay.Api.php";
  11 +require_once 'log.php';
  12 +
  13 +//初始化日志
  14 +$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  15 +$log = Log::Init($logHandler, 15);
  16 +
  17 +
  18 +function printf_info($data)
  19 +{
  20 + foreach($data as $key=>$value){
  21 + echo "<font color='#f00;'>$key</font> : $value <br/>";
  22 + }
  23 +}
  24 +
  25 +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
  26 + $transaction_id = $_REQUEST["transaction_id"];
  27 + $input = new WxPayRefundQuery();
  28 + $input->SetTransaction_id($transaction_id);
  29 + printf_info(WxPayApi::refundQuery($input));
  30 +}
  31 +
  32 +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
  33 + $out_trade_no = $_REQUEST["out_trade_no"];
  34 + $input = new WxPayRefundQuery();
  35 + $input->SetOut_trade_no($out_trade_no);
  36 + printf_info(WxPayApi::refundQuery($input));
  37 + exit();
  38 +}
  39 +
  40 +if(isset($_REQUEST["out_refund_no"]) && $_REQUEST["out_refund_no"] != ""){
  41 + $out_refund_no = $_REQUEST["out_refund_no"];
  42 + $input = new WxPayRefundQuery();
  43 + $input->SetOut_refund_no($out_refund_no);
  44 + printf_info(WxPayApi::refundQuery($input));
  45 + exit();
  46 +}
  47 +
  48 +if(isset($_REQUEST["refund_id"]) && $_REQUEST["refund_id"] != ""){
  49 + $refund_id = $_REQUEST["refund_id"];
  50 + $input = new WxPayRefundQuery();
  51 + $input->SetRefund_id($refund_id);
  52 + printf_info(WxPayApi::refundQuery($input));
  53 + exit();
  54 +}
  55 +
  56 +?>
  57 +<body>
  58 + <form action="#" method="post">
  59 + <div style="margin-left:2%;color:#f00">微信订单号、商户订单号、微信订单号、微信退款单号选填至少一个,微信退款单号优先:</div><br/>
  60 + <div style="margin-left:2%;">微信订单号:</div><br/>
  61 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
  62 + <div style="margin-left:2%;">商户订单号:</div><br/>
  63 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
  64 + <div style="margin-left:2%;">商户退款单号:</div><br/>
  65 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_refund_no" /><br /><br />
  66 + <div style="margin-left:2%;">微信退款单号:</div><br/>
  67 + <input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_id" /><br /><br />
  68 + <div align="center">
  69 + <input type="submit" value="查询" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
  70 + </div>
  71 + </form>
  72 +</body>
  73 +</html>
  1 +<html>
  2 +<head>
  3 + <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1"/>
  5 + <title>微信支付样例</title>
  6 + <style type="text/css">
  7 + ul {
  8 + margin-left:10px;
  9 + margin-right:10px;
  10 + margin-top:10px;
  11 + padding: 0;
  12 + }
  13 + li {
  14 + width: 32%;
  15 + float: left;
  16 + margin: 0px;
  17 + margin-left:1%;
  18 + padding: 0px;
  19 + height: 100px;
  20 + display: inline;
  21 + line-height: 100px;
  22 + color: #fff;
  23 + font-size: x-large;
  24 + word-break:break-all;
  25 + word-wrap : break-word;
  26 + margin-bottom: 5px;
  27 + }
  28 + a {
  29 + -webkit-tap-highlight-color: rgba(0,0,0,0);
  30 + text-decoration:none;
  31 + color:#fff;
  32 + }
  33 + a:link{
  34 + -webkit-tap-highlight-color: rgba(0,0,0,0);
  35 + text-decoration:none;
  36 + color:#fff;
  37 + }
  38 + a:visited{
  39 + -webkit-tap-highlight-color: rgba(0,0,0,0);
  40 + text-decoration:none;
  41 + color:#fff;
  42 + }
  43 + a:hover{
  44 + -webkit-tap-highlight-color: rgba(0,0,0,0);
  45 + text-decoration:none;
  46 + color:#fff;
  47 + }
  48 + a:active{
  49 + -webkit-tap-highlight-color: rgba(0,0,0,0);
  50 + text-decoration:none;
  51 + color:#fff;
  52 + }
  53 + </style>
  54 +</head>
  55 +<body>
  56 + <div align="center">
  57 + <ul>
  58 + <li style="background-color:#FF7F24"><a href="http://paysdk.weixin.qq.com/example/jsapi.php">JSAPI支付</a></li>
  59 + <li style="background-color:#698B22"><a href="http://paysdk.weixin.qq.com/example/micropay.php">刷卡支付</a></li>
  60 + <li style="background-color:#8B6914"><a href="http://paysdk.weixin.qq.com/example/native.php">扫码支付</a></li>
  61 + <li style="background-color:#CDCD00"><a href="http://paysdk.weixin.qq.com/example/orderquery.php">订单查询</a></li>
  62 + <li style="background-color:#CD3278"><a href="http://paysdk.weixin.qq.com/example/refund.php">订单退款</a></li>
  63 + <li style="background-color:#848484"><a href="http://paysdk.weixin.qq.com/example/refundquery.php">退款查询</a></li>
  64 + <li style="background-color:#8EE5EE"><a href="http://paysdk.weixin.qq.com/example/download.php">下载订单</a></li>
  65 + </ul>
  66 + </div>
  67 +</body>
  68 +</html>
  1 +<?php
  2 +require_once "WxPay.Exception.php";
  3 +require_once "WxPay.Config.php";
  4 +require_once "WxPay.Data.php";
  5 +
  6 +/**
  7 + *
  8 + * 接口访问类,包含所有微信支付API列表的封装,类中方法为static方法,
  9 + * 每个接口有默认超时时间(除提交被扫支付为10s,上报超时时间为1s外,其他均为6s)
  10 + * @author widyhu
  11 + *
  12 + */
  13 +class WxPayApi
  14 +{
  15 + /**
  16 + *
  17 + * 统一下单,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
  18 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  19 + * @param WxPayUnifiedOrder $inputObj
  20 + * @param int $timeOut
  21 + * @throws WxPayException
  22 + * @return 成功时返回,其他抛异常
  23 + */
  24 + public static function unifiedOrder($inputObj, $timeOut = 6)
  25 + {
  26 + $url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
  27 + //检测必填参数
  28 + if(!$inputObj->IsOut_trade_noSet()) {
  29 + throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
  30 + }else if(!$inputObj->IsBodySet()){
  31 + throw new WxPayException("缺少统一支付接口必填参数body!");
  32 + }else if(!$inputObj->IsTotal_feeSet()) {
  33 + throw new WxPayException("缺少统一支付接口必填参数total_fee!");
  34 + }else if(!$inputObj->IsTrade_typeSet()) {
  35 + throw new WxPayException("缺少统一支付接口必填参数trade_type!");
  36 + }
  37 +
  38 + //关联参数
  39 + if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
  40 + throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
  41 + }
  42 + if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
  43 + throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
  44 + }
  45 +
  46 + //异步通知url未设置,则使用配置文件中的url
  47 + if(!$inputObj->IsNotify_urlSet()){
  48 + $inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);//异步通知url
  49 + }
  50 +
  51 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  52 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  53 + $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
  54 + //$inputObj->SetSpbill_create_ip("1.1.1.1");
  55 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  56 +
  57 + //签名
  58 + $inputObj->SetSign();
  59 + $xml = $inputObj->ToXml();
  60 +
  61 + $startTimeStamp = self::getMillisecond();//请求开始时间
  62 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  63 + $result = WxPayResults::Init($response);
  64 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  65 +
  66 + return $result;
  67 + }
  68 +
  69 + /**
  70 + *
  71 + * 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
  72 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  73 + * @param WxPayOrderQuery $inputObj
  74 + * @param int $timeOut
  75 + * @throws WxPayException
  76 + * @return 成功时返回,其他抛异常
  77 + */
  78 + public static function orderQuery($inputObj, $timeOut = 6)
  79 + {
  80 + $url = "https://api.mch.weixin.qq.com/pay/orderquery";
  81 + //检测必填参数
  82 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
  83 + throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
  84 + }
  85 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  86 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  87 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  88 +
  89 + $inputObj->SetSign();//签名
  90 + $xml = $inputObj->ToXml();
  91 +
  92 + $startTimeStamp = self::getMillisecond();//请求开始时间
  93 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  94 + $result = WxPayResults::Init($response);
  95 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  96 +
  97 + return $result;
  98 + }
  99 +
  100 + /**
  101 + *
  102 + * 关闭订单,WxPayCloseOrder中out_trade_no必填
  103 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  104 + * @param WxPayCloseOrder $inputObj
  105 + * @param int $timeOut
  106 + * @throws WxPayException
  107 + * @return 成功时返回,其他抛异常
  108 + */
  109 + public static function closeOrder($inputObj, $timeOut = 6)
  110 + {
  111 + $url = "https://api.mch.weixin.qq.com/pay/closeorder";
  112 + //检测必填参数
  113 + if(!$inputObj->IsOut_trade_noSet()) {
  114 + throw new WxPayException("订单查询接口中,out_trade_no必填!");
  115 + }
  116 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  117 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  118 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  119 +
  120 + $inputObj->SetSign();//签名
  121 + $xml = $inputObj->ToXml();
  122 +
  123 + $startTimeStamp = self::getMillisecond();//请求开始时间
  124 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  125 + $result = WxPayResults::Init($response);
  126 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  127 +
  128 + return $result;
  129 + }
  130 +
  131 + /**
  132 + *
  133 + * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
  134 + * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
  135 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  136 + * @param WxPayRefund $inputObj
  137 + * @param int $timeOut
  138 + * @throws WxPayException
  139 + * @return 成功时返回,其他抛异常
  140 + */
  141 + public static function refund($inputObj, $timeOut = 6)
  142 + {
  143 + $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
  144 + //检测必填参数
  145 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
  146 + throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
  147 + }else if(!$inputObj->IsOut_refund_noSet()){
  148 + throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
  149 + }else if(!$inputObj->IsTotal_feeSet()){
  150 + throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
  151 + }else if(!$inputObj->IsRefund_feeSet()){
  152 + throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
  153 + }else if(!$inputObj->IsOp_user_idSet()){
  154 + throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
  155 + }
  156 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  157 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  158 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  159 +
  160 + $inputObj->SetSign();//签名
  161 + $xml = $inputObj->ToXml();
  162 + $startTimeStamp = self::getMillisecond();//请求开始时间
  163 + $response = self::postXmlCurl($xml, $url, true, $timeOut);
  164 + $result = WxPayResults::Init($response);
  165 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  166 +
  167 + return $result;
  168 + }
  169 +
  170 + /**
  171 + *
  172 + * 查询退款
  173 + * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,
  174 + * 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
  175 + * WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
  176 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  177 + * @param WxPayRefundQuery $inputObj
  178 + * @param int $timeOut
  179 + * @throws WxPayException
  180 + * @return 成功时返回,其他抛异常
  181 + */
  182 + public static function refundQuery($inputObj, $timeOut = 6)
  183 + {
  184 + $url = "https://api.mch.weixin.qq.com/pay/refundquery";
  185 + //检测必填参数
  186 + if(!$inputObj->IsOut_refund_noSet() &&
  187 + !$inputObj->IsOut_trade_noSet() &&
  188 + !$inputObj->IsTransaction_idSet() &&
  189 + !$inputObj->IsRefund_idSet()) {
  190 + throw new WxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
  191 + }
  192 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  193 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  194 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  195 +
  196 + $inputObj->SetSign();//签名
  197 + $xml = $inputObj->ToXml();
  198 +
  199 + $startTimeStamp = self::getMillisecond();//请求开始时间
  200 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  201 + $result = WxPayResults::Init($response);
  202 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  203 +
  204 + return $result;
  205 + }
  206 +
  207 + /**
  208 + * 下载对账单,WxPayDownloadBill中bill_date为必填参数
  209 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  210 + * @param WxPayDownloadBill $inputObj
  211 + * @param int $timeOut
  212 + * @throws WxPayException
  213 + * @return 成功时返回,其他抛异常
  214 + */
  215 + public static function downloadBill($inputObj, $timeOut = 6)
  216 + {
  217 + $url = "https://api.mch.weixin.qq.com/pay/downloadbill";
  218 + //检测必填参数
  219 + if(!$inputObj->IsBill_dateSet()) {
  220 + throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
  221 + }
  222 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  223 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  224 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  225 +
  226 + $inputObj->SetSign();//签名
  227 + $xml = $inputObj->ToXml();
  228 +
  229 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  230 + if(substr($response, 0 , 5) == "<xml>"){
  231 + return "";
  232 + }
  233 + return $response;
  234 + }
  235 +
  236 + /**
  237 + * 提交被扫支付API
  238 + * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
  239 + * 由商户收银台或者商户后台调用该接口发起支付。
  240 + * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
  241 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  242 + * @param WxPayWxPayMicroPay $inputObj
  243 + * @param int $timeOut
  244 + */
  245 + public static function micropay($inputObj, $timeOut = 10)
  246 + {
  247 + $url = "https://api.mch.weixin.qq.com/pay/micropay";
  248 + //检测必填参数
  249 + if(!$inputObj->IsBodySet()) {
  250 + throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
  251 + } else if(!$inputObj->IsOut_trade_noSet()) {
  252 + throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
  253 + } else if(!$inputObj->IsTotal_feeSet()) {
  254 + throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
  255 + } else if(!$inputObj->IsAuth_codeSet()) {
  256 + throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
  257 + }
  258 +
  259 + $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
  260 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  261 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  262 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  263 +
  264 + $inputObj->SetSign();//签名
  265 + $xml = $inputObj->ToXml();
  266 +
  267 + $startTimeStamp = self::getMillisecond();//请求开始时间
  268 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  269 + $result = WxPayResults::Init($response);
  270 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  271 +
  272 + return $result;
  273 + }
  274 +
  275 + /**
  276 + *
  277 + * 撤销订单API接口,WxPayReverse中参数out_trade_no和transaction_id必须填写一个
  278 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  279 + * @param WxPayReverse $inputObj
  280 + * @param int $timeOut
  281 + * @throws WxPayException
  282 + */
  283 + public static function reverse($inputObj, $timeOut = 6)
  284 + {
  285 + $url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
  286 + //检测必填参数
  287 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
  288 + throw new WxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
  289 + }
  290 +
  291 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  292 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  293 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  294 +
  295 + $inputObj->SetSign();//签名
  296 + $xml = $inputObj->ToXml();
  297 +
  298 + $startTimeStamp = self::getMillisecond();//请求开始时间
  299 + $response = self::postXmlCurl($xml, $url, true, $timeOut);
  300 + $result = WxPayResults::Init($response);
  301 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  302 +
  303 + return $result;
  304 + }
  305 +
  306 + /**
  307 + *
  308 + * 测速上报,该方法内部封装在report中,使用时请注意异常流程
  309 + * WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
  310 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  311 + * @param WxPayReport $inputObj
  312 + * @param int $timeOut
  313 + * @throws WxPayException
  314 + * @return 成功时返回,其他抛异常
  315 + */
  316 + public static function report($inputObj, $timeOut = 1)
  317 + {
  318 + $url = "https://api.mch.weixin.qq.com/payitil/report";
  319 + //检测必填参数
  320 + if(!$inputObj->IsInterface_urlSet()) {
  321 + throw new WxPayException("接口URL,缺少必填参数interface_url!");
  322 + } if(!$inputObj->IsReturn_codeSet()) {
  323 + throw new WxPayException("返回状态码,缺少必填参数return_code!");
  324 + } if(!$inputObj->IsResult_codeSet()) {
  325 + throw new WxPayException("业务结果,缺少必填参数result_code!");
  326 + } if(!$inputObj->IsUser_ipSet()) {
  327 + throw new WxPayException("访问接口IP,缺少必填参数user_ip!");
  328 + } if(!$inputObj->IsExecute_time_Set()) {
  329 + throw new WxPayException("接口耗时,缺少必填参数execute_time_!");
  330 + }
  331 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  332 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  333 + $inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
  334 + $inputObj->SetTime(date("YmdHis"));//商户上报时间
  335 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  336 +
  337 + $inputObj->SetSign();//签名
  338 + $xml = $inputObj->ToXml();
  339 +
  340 + $startTimeStamp = self::getMillisecond();//请求开始时间
  341 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  342 + return $response;
  343 + }
  344 +
  345 + /**
  346 + *
  347 + * 生成二维码规则,模式一生成支付二维码
  348 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  349 + * @param WxPayBizPayUrl $inputObj
  350 + * @param int $timeOut
  351 + * @throws WxPayException
  352 + * @return 成功时返回,其他抛异常
  353 + */
  354 + public static function bizpayurl($inputObj, $timeOut = 6)
  355 + {
  356 + if(!$inputObj->IsProduct_idSet()){
  357 + throw new WxPayException("生成二维码,缺少必填参数product_id!");
  358 + }
  359 +
  360 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  361 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  362 + $inputObj->SetTime_stamp(time());//时间戳
  363 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  364 +
  365 + $inputObj->SetSign();//签名
  366 +
  367 + return $inputObj->GetValues();
  368 + }
  369 +
  370 + /**
  371 + *
  372 + * 转换短链接
  373 + * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  374 + * 减小二维码数据量,提升扫描速度和精确度。
  375 + * appid、mchid、spbill_create_ip、nonce_str不需要填入
  376 + * @param WxPayShortUrl $inputObj
  377 + * @param int $timeOut
  378 + * @throws WxPayException
  379 + * @return 成功时返回,其他抛异常
  380 + */
  381 + public static function shorturl($inputObj, $timeOut = 6)
  382 + {
  383 + $url = "https://api.mch.weixin.qq.com/tools/shorturl";
  384 + //检测必填参数
  385 + if(!$inputObj->IsLong_urlSet()) {
  386 + throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
  387 + }
  388 + $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
  389 + $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
  390 + $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
  391 +
  392 + $inputObj->SetSign();//签名
  393 + $xml = $inputObj->ToXml();
  394 +
  395 + $startTimeStamp = self::getMillisecond();//请求开始时间
  396 + $response = self::postXmlCurl($xml, $url, false, $timeOut);
  397 + $result = WxPayResults::Init($response);
  398 + self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
  399 +
  400 + return $result;
  401 + }
  402 +
  403 + /**
  404 + *
  405 + * 支付结果通用通知
  406 + * @param function $callback
  407 + * 直接回调函数使用方法: notify(you_function);
  408 + * 回调类成员函数方法:notify(array($this, you_function));
  409 + * $callback 原型为:function function_name($data){}
  410 + */
  411 + public static function notify($callback, &$msg)
  412 + {
  413 + //获取通知的数据
  414 + $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
  415 + //如果返回成功则验证签名
  416 + try {
  417 + $result = WxPayResults::Init($xml);
  418 + } catch (WxPayException $e){
  419 + $msg = $e->errorMessage();
  420 + return false;
  421 + }
  422 +
  423 + return call_user_func($callback, $result);
  424 + }
  425 +
  426 + /**
  427 + *
  428 + * 产生随机字符串,不长于32位
  429 + * @param int $length
  430 + * @return 产生的随机字符串
  431 + */
  432 + public static function getNonceStr($length = 32)
  433 + {
  434 + $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  435 + $str ="";
  436 + for ( $i = 0; $i < $length; $i++ ) {
  437 + $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
  438 + }
  439 + return $str;
  440 + }
  441 +
  442 + /**
  443 + * 直接输出xml
  444 + * @param string $xml
  445 + */
  446 + public static function replyNotify($xml)
  447 + {
  448 + echo $xml;
  449 + }
  450 +
  451 + /**
  452 + *
  453 + * 上报数据, 上报的时候将屏蔽所有异常流程
  454 + * @param string $usrl
  455 + * @param int $startTimeStamp
  456 + * @param array $data
  457 + */
  458 + private static function reportCostTime($url, $startTimeStamp, $data)
  459 + {
  460 + //如果不需要上报数据
  461 + if(WxPayConfig::REPORT_LEVENL == 0){
  462 + return;
  463 + }
  464 + //如果仅失败上报
  465 + if(WxPayConfig::REPORT_LEVENL == 1 &&
  466 + array_key_exists("return_code", $data) &&
  467 + $data["return_code"] == "SUCCESS" &&
  468 + array_key_exists("result_code", $data) &&
  469 + $data["result_code"] == "SUCCESS")
  470 + {
  471 + return;
  472 + }
  473 +
  474 + //上报逻辑
  475 + $endTimeStamp = self::getMillisecond();
  476 + $objInput = new WxPayReport();
  477 + $objInput->SetInterface_url($url);
  478 + $objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
  479 + //返回状态码
  480 + if(array_key_exists("return_code", $data)){
  481 + $objInput->SetReturn_code($data["return_code"]);
  482 + }
  483 + //返回信息
  484 + if(array_key_exists("return_msg", $data)){
  485 + $objInput->SetReturn_msg($data["return_msg"]);
  486 + }
  487 + //业务结果
  488 + if(array_key_exists("result_code", $data)){
  489 + $objInput->SetResult_code($data["result_code"]);
  490 + }
  491 + //错误代码
  492 + if(array_key_exists("err_code", $data)){
  493 + $objInput->SetErr_code($data["err_code"]);
  494 + }
  495 + //错误代码描述
  496 + if(array_key_exists("err_code_des", $data)){
  497 + $objInput->SetErr_code_des($data["err_code_des"]);
  498 + }
  499 + //商户订单号
  500 + if(array_key_exists("out_trade_no", $data)){
  501 + $objInput->SetOut_trade_no($data["out_trade_no"]);
  502 + }
  503 + //设备号
  504 + if(array_key_exists("device_info", $data)){
  505 + $objInput->SetDevice_info($data["device_info"]);
  506 + }
  507 +
  508 + try{
  509 + self::report($objInput);
  510 + } catch (WxPayException $e){
  511 + //不做任何处理
  512 + }
  513 + }
  514 +
  515 + /**
  516 + * 以post方式提交xml到对应的接口url
  517 + *
  518 + * @param string $xml 需要post的xml数据
  519 + * @param string $url url
  520 + * @param bool $useCert 是否需要证书,默认不需要
  521 + * @param int $second url执行超时时间,默认30s
  522 + * @throws WxPayException
  523 + */
  524 + private static function postXmlCurl($xml, $url, $useCert = false, $second = 30)
  525 + {
  526 + $ch = curl_init();
  527 + //设置超时
  528 + curl_setopt($ch, CURLOPT_TIMEOUT, $second);
  529 +
  530 + //如果有配置代理这里就设置代理
  531 + if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
  532 + && WxPayConfig::CURL_PROXY_PORT != 0){
  533 + curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
  534 + curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
  535 + }
  536 + curl_setopt($ch,CURLOPT_URL, $url);
  537 + curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
  538 + curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
  539 + //设置header
  540 + curl_setopt($ch, CURLOPT_HEADER, FALSE);
  541 + //要求结果为字符串且输出到屏幕上
  542 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  543 +
  544 + if($useCert == true){
  545 + //设置证书
  546 + //使用证书:cert 与 key 分别属于两个.pem文件
  547 + curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
  548 + curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
  549 + curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
  550 + curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
  551 + }
  552 + //post提交方式
  553 + curl_setopt($ch, CURLOPT_POST, TRUE);
  554 + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  555 + //运行curl
  556 + $data = curl_exec($ch);
  557 + //返回结果
  558 + if($data){
  559 + curl_close($ch);
  560 + return $data;
  561 + } else {
  562 + $error = curl_errno($ch);
  563 + curl_close($ch);
  564 + throw new WxPayException("curl出错,错误码:$error");
  565 + }
  566 + }
  567 +
  568 + /**
  569 + * 获取毫秒级别的时间戳
  570 + */
  571 + private static function getMillisecond()
  572 + {
  573 + //获取毫秒的时间戳
  574 + $time = explode ( " ", microtime () );
  575 + $time = $time[1] . ($time[0] * 1000);
  576 + $time2 = explode( ".", $time );
  577 + $time = $time2[0];
  578 + return $time;
  579 + }
  580 +}
  581 +
  1 +<?php
  2 +/**
  3 +* 配置账号信息
  4 +*/
  5 +
  6 +class WxPayConfig
  7 +{
  8 + //=======【基本信息设置】=====================================
  9 + //
  10 + /**
  11 + * TODO: 修改这里配置为您自己申请的商户信息
  12 + * 微信公众号信息配置
  13 + *
  14 + * APPID:绑定支付的APPID(必须配置,开户邮件中可查看)
  15 + *
  16 + * MCHID:商户号(必须配置,开户邮件中可查看)
  17 + *
  18 + * KEY:商户支付密钥,参考开户邮件设置(必须配置,登录商户平台自行设置)
  19 + * 设置地址:https://pay.weixin.qq.com/index.php/account/api_cert
  20 + *
  21 + * APPSECRET:公众帐号secert(仅JSAPI支付的时候需要配置, 登录公众平台,进入开发者中心可设置),
  22 + * 获取地址:https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=2005451881&lang=zh_CN
  23 + * @var string
  24 + */
  25 + const APPID = 'wxf69d1d87d173c899';
  26 + const MCHID = '1507884301';
  27 + const KEY = 'YkeE7j21vdwqnBYW8FM2Z11O9T4v1kH0';
  28 + const APPSECRET = '93c020c51020d87bda1c0bd98b527ff5';
  29 +
  30 + //=======【证书路径设置】=====================================
  31 + /**
  32 + * TODO:设置商户证书路径
  33 + * 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,
  34 + * API证书下载地址:https://pay.weixin.qq.com/index.php/account/api_cert,下载之前需要安装商户操作证书)
  35 + * @var path
  36 + */
  37 + const SSLCERT_PATH = '../cert/apiclient_cert.pem';
  38 + const SSLKEY_PATH = '../cert/apiclient_key.pem';
  39 +
  40 + //=======【curl代理设置】===================================
  41 + /**
  42 + * TODO:这里设置代理机器,只有需要代理的时候才设置,不需要代理,请设置为0.0.0.0和0
  43 + * 本例程通过curl使用HTTP POST方法,此处可修改代理服务器,
  44 + * 默认CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0,此时不开启代理(如有需要才设置)
  45 + * @var unknown_type
  46 + */
  47 + const CURL_PROXY_HOST = "0.0.0.0";//"10.152.18.220";
  48 + const CURL_PROXY_PORT = 0;//8080;
  49 +
  50 + //=======【上报信息配置】===================================
  51 + /**
  52 + * TODO:接口调用上报等级,默认紧错误上报(注意:上报超时间为【1s】,上报无论成败【永不抛出异常】,
  53 + * 不会影响接口调用流程),开启上报之后,方便微信监控请求调用的质量,建议至少
  54 + * 开启错误上报。
  55 + * 上报等级,0.关闭上报; 1.仅错误出错上报; 2.全量上报
  56 + * @var int
  57 + */
  58 + const REPORT_LEVENL = 1;
  59 +}