config = new \Cmbc\Setting(); # 通知接口 $config['notify'] = $this->url($config['type'], $config['id']); # 证书 $config['ssl'] = array ( 'cert' => $config['file_cert'], 'key' => $config['file_key'], ); $this->config->set($config['appid'], $config['appsecret'], $config['mchid'], $config['notify'], $config['key'], $config['ssl'], $config['type'], $config['timeout']); } /** * 通知 */ public function notify() { $input = file_get_contents("php://input"); if ($input) { parse_str($input, $input); } else { $input = Dever::input(); } $this->log('支付回调-初始化', $input); $tools = new \Cmbc\Handle(); $callback = $tools->get('notify', $this->config); $result = $callback->request($input, $this); if ($result) { $this->log('支付回调-获取数据', $result); $this->updateOrder($result['mhtOrderNo'], $result['mhtOrderAmt']); echo 'success=Y';die; } else { echo 'success=N';die; } } /** * 获取统一下单的基本信息 */ public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false) { $trade_type = $this->getType($type); $order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config->GetType(), $order_id); $tools = new \Cmbc\Handle(); $order = $tools->get('order', $this->config); $request['mhtOrderNo'] = $order_id; $request['mhtOrderName'] = $name; $request['mhtOrderAmt'] = $cash * 100; $request['mhtOrderDetail'] = $name; $request['mhtOrderStartTime'] = date("YmdHis"); $request['notifyUrl'] = $this->config->getNotifyUrl(); $request['outputType'] = 1; if (!$openid) { $request['consumerId'] = 'ofBUV0RUoy_8C4VctZjrSDGzhUfY'; } else { $request['consumerId'] = $openid; } $result = $order->request($request); $this->updateOrderParam($order_id, $result); return $result; } /** * 获取二维码支付 */ public function qrcode($order, $refer) { $notify = new \NativePay(); $result = $notify->GetPayUrl($order); $url = $result['code_url']; return array ( 'url' => $url, 'type' => 'qrcode', ); return $url; } /** * 获取小程序支付 */ public function applet($order) { $result = array(); if (isset($order['prepay_id'])) { $result['time'] = $order['timeStamp']; $result['nonce_str'] = $order['nonceStr']; $result['prepay_id'] = $order['prepay_id']; $result['sign_type'] = $order['signType']; $result['sign'] = $order['paySign']; $result['type'] = 'applet'; } return $result; } /** * 获取页面支付 */ public function page($order, $refer) { $refer = urldecode($refer); $tools = new \JsApiPay($this->config); $info = $tools->GetJsApiParameters($order); $html = ''; return $html; } private function getType($type) { switch ($type) { case 1: $type = 'JSAPI'; break; case 2: $type = 'NATIVE'; break; case 3: $type = 'APP'; break; case 4: $type = 'MWEB'; break; } return $type; } }