|
@@ -0,0 +1,155 @@
|
|
|
+<?php namespace Pay\Lib;
|
|
|
+use Dever;
|
|
|
+Dever::apply('sdk/cmbc', 'pay');
|
|
|
+
|
|
|
+class Cmbc extends Core
|
|
|
+{
|
|
|
+ public function __construct($config)
|
|
|
+ {
|
|
|
+ $project = Dever::project('pay');
|
|
|
+ $this->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()
|
|
|
+ {
|
|
|
+ $this->log('支付回调-初始化', file_get_contents("php://input"));
|
|
|
+ $tools = new \Cmbc\Handle();
|
|
|
+ $callback = $tools->get('notify', $this->config);
|
|
|
+ $result = $callback->request(Dever::input(), $this);
|
|
|
+ print_r($result);die;
|
|
|
+ $this->log('支付回调-获取数据', $result);
|
|
|
+ $this->updateOrder($result['mhtOrderNo'], $result['mhtOrderAmt'], $msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取统一下单的基本信息
|
|
|
+ */
|
|
|
+ public function order($account_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false)
|
|
|
+ {
|
|
|
+ $trade_type = $this->getType($type);
|
|
|
+ $order_id = $this->createOrder($uid, $username, $account_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;
|
|
|
+ $request['mhtSubAppId'] = '?';
|
|
|
+ $request['consumerId'] = $openid;
|
|
|
+
|
|
|
+ $result = $order->request($request);
|
|
|
+ print_r($result);die;
|
|
|
+ $this->updateOrderParam($order_id, $result);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取二维码支付
|
|
|
+ */
|
|
|
+ public function qrcode($order, $refer)
|
|
|
+ {
|
|
|
+ $notify = new \NativePay();
|
|
|
+ $result = $notify->GetPayUrl($order);
|
|
|
+ $url = $result['code_url'];
|
|
|
+ return $url;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取小程序支付
|
|
|
+ */
|
|
|
+ public function applet($order)
|
|
|
+ {
|
|
|
+ if (isset($order['prepay_id'])) {
|
|
|
+
|
|
|
+ $string = 'appId='.$this->config->getAppId().'&nonceStr='.$order['nonce_str'].'&package=prepay_id='.$order['prepay_id'].'&signType='.$order['sign_type'].'&timeStamp='.$order['time'].'&key='.$this->config->getKey();
|
|
|
+ if($order['sign_type'] == "MD5"){
|
|
|
+ $string = md5($string);
|
|
|
+ } else {
|
|
|
+ $string = hash_hmac("sha256", $string, $this->config->getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ $order['sign'] = $string;
|
|
|
+ }
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取页面支付
|
|
|
+ */
|
|
|
+ public function page($order, $refer)
|
|
|
+ {
|
|
|
+ $refer = urldecode($refer);
|
|
|
+ $tools = new \JsApiPay($this->config);
|
|
|
+ $info = $tools->GetJsApiParameters($order);
|
|
|
+
|
|
|
+ $html = '<script type="text/javascript">
|
|
|
+ function jsApiCall()
|
|
|
+ {
|
|
|
+ WeixinJSBridge.invoke(
|
|
|
+ "getBrandWCPayRequest",
|
|
|
+ '.$info.',
|
|
|
+ function(res){
|
|
|
+ //WeixinJSBridge.log(res.err_msg);
|
|
|
+ if(res.err_msg == "get_brand_wcpay_request:ok")
|
|
|
+ {
|
|
|
+ location.href = "'.$refer.'";
|
|
|
+ } else {
|
|
|
+ alert(res.err_code+res.err_desc+res.err_msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ function callpay()
|
|
|
+ {
|
|
|
+ if (typeof WeixinJSBridge == "undefined"){
|
|
|
+ if( document.addEventListener ){
|
|
|
+ document.addEventListener("WeixinJSBridgeReady", jsApiCall, false);
|
|
|
+ }else if (document.attachEvent){
|
|
|
+ document.attachEvent("WeixinJSBridgeReady", jsApiCall);
|
|
|
+ document.attachEvent("onWeixinJSBridgeReady", jsApiCall);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ jsApiCall();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callpay();
|
|
|
+ </script>';
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getType($type)
|
|
|
+ {
|
|
|
+ switch ($type) {
|
|
|
+ case 1:
|
|
|
+ $type = 'JSAPI';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2:
|
|
|
+ $type = 'NATIVE';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $type;
|
|
|
+ }
|
|
|
+}
|