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); }
function pay() { 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 . ',返回到微信主界面即可领取'; $result['money'] = $prize; // 红包活动id $id = $this->_get('id'); // 获得openid $ucode = $this->_post('ucode'); $log = array(); $log['token'] = $this->token; $log['wecha_id'] = $ucode; $log['packet_id'] = $id; $log['prize_name'] = $prize_name; $log['worth'] = $prize; $log['add_time'] = time(); $log['type'] = $this->packet_info['packet_type']; $md5 = $ucode . $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(); $payarr['amount'] = 1; // 红包金额,单位为分 $pay->mch_pay($ucode, null, $payarr); exit; } else { $result['err'] = 5; $result['msg'] = '未知错误,请稍后再试'; $result['type'] = $this->packet_info['packet_type']; $result['prize'] = $prize; echo json_encode($result); exit; } }