Thinkphp和onethink實現微信支付外掛程式,thinkphponethink_PHP教程

來源:互聯網
上載者:User

Thinkphp和onethink實現支付外掛程式,thinkphponethink


thinkPHP和微支付實現的支付外掛程式,在中調用jssdk實現支付,這裡有詳細的代碼和教程,具體看這裡:

//實現的Wxpay鉤子方法    public function Wxpay($param){      require './Addons/Wxpay/WxPayPubHelper/WxPayPubHelper.php';      $jsApi = new \JsApi_pub();              //=========步驟1:網頁授權擷取使用者openid============      if (!isset($_GET['code']))      {        //觸發返回code碼        $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL.'/order_id/'.$param['order_id']);        Header("Location: $url");      }else      {        $order_id = $param['order_id'];        $info = M('Order')->where('id='.$order_id)->find();        if(empty($info) || $info['is_pay'] == 1){          dump('該訂單不存在或已支付'.$order_id);          exit();        }        $this->assign('info', $info);        $a = $info['money'];        $b = 100;        $c = $a * $b;                 //擷取code碼,以擷取openid        $code = $_GET['code'];        $jsApi->setCode($code);        $openid = $jsApi->getOpenId();      }             //=========步驟2:使用統一支付介面,擷取prepay_id============      //使用統一支付介面      $unifiedOrder = new \UnifiedOrder_pub();             $unifiedOrder->setParameter("openid","$openid");//商品描述      $unifiedOrder->setParameter("body","線上預訂");//商品描述      //自訂訂單號,此處僅作舉例      $timeStamp = time();//       $out_trade_no = \WxPayConf_pub::APPID."$timeStamp";      $out_trade_no = $info['ordersn'];      $unifiedOrder->setParameter("out_trade_no", "$out_trade_no");//商戶訂單號      $unifiedOrder->setParameter("total_fee", "$c");//總金額      $unifiedOrder->setParameter("notify_url",\WxPayConf_pub::NOTIFY_URL.'/order_id/'.$param['order_id']);//通知地址      $unifiedOrder->setParameter("trade_type","JSAPI");//交易類型             $prepay_id = $unifiedOrder->getPrepayId();      //=========步驟3:使用jsapi調起支付============      $jsApi->setPrepayId($prepay_id);      $jsApiParameters = $jsApi->getParameters();      $this->assign('jsApiParameters', $jsApiParameters);       $this->display('pay');    }

以上就是本文的全部內容,希望對大家學習PHP程式設計有所協助。

您可能感興趣的文章:

  • 什麼是OneThink oneThink後台添加外掛程式步驟

http://www.bkjia.com/PHPjc/1119960.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1119960.htmlTechArticleThinkphp和onethink實現支付外掛程式,thinkphponethink thinkPHP和微支付實現的支付外掛程式,在中調用jssdk實現支付,這裡有詳細的代碼和...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.