public function mch_pay_test() { // vendor vendor('WxPay.class#wxpay'); $pay = new WxPay(); $_payarr['amount'] = 1; // o7F8auDz4SGsyIkBov3pWzA2C4jE // o7F8auFB-s2WRNRcskQOI7Ap-Mn8 // f**k $pay->mch_pay('o7F8auDz4SGsyIkBov3pWzA2C4jE', null, $_payarr); }
//引入函数文件 require_once './Api/Function.php'; //print_r($config);die(); //获取openid $openid = get_openid(); //订单描述 $body = '无描述'; //生成订单号 $out_trade_no = date("YmdHis") . rand(100, 999); //---------------价格(1代表1分钱,1块钱就*100)--------------- $total_fee = 1; //回调地址 $notify_url = 'http://www.baidu.com'; //dump($notify_url);exit; //使用统一支付接口,获取prepay_id $wxp = new WxPay($config['KEY']); $wxp->setParameter("openid", $openid); $wxp->setParameter("appid", $config['APPID']); $wxp->setParameter("mch_id", $config['MCHID']); $wxp->setParameter("notify_url", $notify_url); $wxp->setParameter("body", $body); $wxp->setParameter("out_trade_no", $out_trade_no); $wxp->setParameter("total_fee", $total_fee); $wxp->setParameter("trade_type", 'JSAPI'); $jsApiParameters = $wxp->getParameters(); //var_dump($jsApiParameters);die(); $html = array(); $html[] = '<script language="javascript">'; $html[] = "\tfunction jsApiCall(){"; //$html[] = " alert(JSON.stringify(".$jsApiParameters."));"; $html[] = "\t\tWeixinJSBridge.invoke(";
function getPacket() { $result = array(); $id = $this->_get('id', 'intval'); $openid = $this->_get('wecha_id'); // echo $openid; if ($this->is_start() == 1) { $result['err'] = 1; $result['msg'] = '活动还没有开始,请耐心等待!'; echo json_encode($result); exit; } if ($this->is_start() == 2) { $result['err'] = 2; $result['msg'] = '活动已经结束,敬请关注下一轮活动开始!'; echo json_encode($result); exit; } $pwhere = array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'packet_id' => $id); $p_count = M('Red_packet_log')->where($pwhere)->count(); /*奖品数量消耗完提示红包被领光*/ if ($p_count >= $this->packet_info['get_number']) { $result['err'] = 3; $result['msg'] = '领取次数已经用光了!<br/>点击“我的红包”查看记录'; echo json_encode($result); exit; } if (!$this->check_packet_type()) { $result['err'] = 4; $result['msg'] = '红包已经领光啦,敬请关注下一轮活动开始!'; echo json_encode($result); exit; } if ($this->packet_info['packet_type'] == '1') { $max = $this->packet_info['item_max']; //单个上限 if ($this->packet_info['deci'] == 0) { $prize = mt_rand(1, $max); } else { if ($this->packet_info['deci'] == 1) { $prize = mt_rand(1, $max * 10) / 10; } else { if ($this->packet_info['deci'] == 2) { //$prize = mt_rand(1,$max*100)/100; $prize = sprintf("%.2f", mt_rand(1, $max * 100) / 100); } } } $prize_name = $prize . '元'; } else { if ($this->packet_info['packet_type'] == '2') { $unit = $this->packet_info['item_unit']; //面额 $prize = $this->packet_info['item_unit']; $prize_name = $prize . '元'; } } $result['err'] = 0; $result['msg'] = '恭喜您抽中了' . $prize_name . ',返回到微信主界面即可领取'; $log = array(); $log['token'] = $this->token; $log['wecha_id'] = $this->wecha_id; $log['packet_id'] = $id; $log['prize_name'] = $prize_name; $log['worth'] = $prize; $log['add_time'] = time(); $log['type'] = $this->packet_info['packet_type']; $md5 = $this->wecha_id . $id . $prize . time(); $log['code'] = substr(md5($md5), 0, 12); $log_id = M('Red_packet_log')->add($log); if ($log_id) { echo json_encode($result); // 这里做发微信红包处理 vendor('WxPay.class#wxpay'); $pay = new WxPay(); if ($prize < 1) { // 如果中奖金额小于100分,做100补齐 $payarr['total_amount'] = 100; $payarr['min_value'] = 100; $payarr['max_value'] = 100; $pay->pay($openid, null, $payarr); } else { // vendor('WxPay.class#wxpay'); // $pay = new WxPay(); // $payarr['total_amount'] = $prize_name * 100; // $payarr['min_value'] = $prize_name * 100; // $payarr['max_value'] = $prize_name * 100; // echo $this->wecha_id; // // $pay->pay('o7F8auB73FIMKIB1RWf_VleZRPfM', null, $payarr); // $pay->pay($this->wecha_id, null, $payarr); $payarr['total_amount'] = $prize * 100; $payarr['min_value'] = $prize * 100; $payarr['max_value'] = $prize * 100; // echo $this->wecha_id; // $pay->pay('o7F8auB73FIMKIB1RWf_VleZRPfM', null, $payarr); $pay->pay($openid, null, $payarr); } exit; } else { $result['err'] = 5; $result['msg'] = '未知错误,请稍后再试'; $result['type'] = $this->packet_info['packet_type']; $result['prize'] = $prize; echo json_encode($result); exit; } }
<?php //微信支付 header("Content-type: application/json; charset=utf-8"); header("Access-Control-Allow-Origin:*"); include_once "wx.pay.php"; $wxPay = new WxPay(); $getUrlParam = function ($key) { if (isset($_GET[$key])) { return $_GET[$key]; } elseif (isset($_POST[$key])) { return $_POST[$key]; } else { $errObj['code'] = -1; $errObj['msg'] = $key . '不存在'; $errObj['data'] = null; echo Util::getJsonString($errObj); exit; } }; $code = $getUrlParam('code'); $product_id = $getUrlParam('product_id'); $price = $getUrlParam('price'); $title = $getUrlParam('title'); $unifiedOrder["product_id"] = $product_id; $unifiedOrder["total_fee"] = $price; $unifiedOrder["body"] = $title; $wxPayArgsObj = $wxPay->getParameters($code, $unifiedOrder); echo Util::getJsonString($wxPayArgsObj);
function actionNotify() { $pay = new WxPay(); $logs = array(); $wxinfoArr = $pay->NotifyInterface(); $logs['wxinfoxml'] = $wxinfoArr['xml']; //log $wxinfo = json_decode(json_encode(simplexml_load_string($wxinfoArr['xml'], 'SimpleXMLElement', LIBXML_NOCDATA)), true); if (1 == intval($wxinfoArr['state'])) { //成功 $tradeno = $wxinfo['out_trade_no']; $logs['addPay-data'] = $wxinfo; $logs['tradeno'] = $tradeno; $this->processByTradeno($tradeno, $wxinfo); } CLog::WriteLog($logs, 'wx-pay'); }