1. 程式人生 > 實用技巧 >php CI框架中的充值程式碼參考

php CI框架中的充值程式碼參考

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Payment extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $this->load->model('accountm');

        /** 支援的充值介面 */
        $this->data['methods'] = ['alipay'];
	}

	/**
     * 支付完成通知頁面,POST請求
     */
	public function notify()
    {
        $result = ( $this->_validate() ? "success" : "fail" );
		echo $result;
		exit();
	}

	/**
     * 支付完成回撥頁面
     */
	public function callback()
    {
		if($this->_validate()) {
			ShowMsg('恭喜,賬戶充值成功', site_url('user/account'));
		} else {
			ShowMsg('非法操作,充值失敗', base_url());
		}
	}

    /**
     * 核對充值結果
     * @return bool
     */
	private function _validate()
    {
        $method = $this->uri->segment(3, '');
        if ( ! in_array($method, $this->data['methods']) ) return FALSE;

        /** 驗證資料 */
        $this->load->config('finance', true);
        $this->load->library("payment/{$method}", NULL, 'Payment');
        return $this->Payment->respond();
    }
}

/* End of file payment.php */
/* Location: ./application/controllers/payment.php */

  一般的應用使用者中心都會使用到的充值的功能,如果覺得二開功能太麻煩了,可以訪問這個網站:https://www.hu-ling.cn讓程式設計師幫忙二開一下!

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Payment extends CI_Controller {
public function __construct() { parent::__construct(); $this->load->model('accountm');
/** 支援的充值介面 */ $this->data['methods'] = ['alipay'];}

/** * 支付完成通知頁面,POST請求 */public function notify() { $result = ( $this->_validate() ? "success" : "fail" );echo $result;exit();}
/** * 支付完成回撥頁面 */public function callback() {if($this->_validate()) {ShowMsg('恭喜,賬戶充值成功', site_url('user/account'));} else {ShowMsg('非法操作,充值失敗', base_url());}}
/** * 核對充值結果 * @return bool */private function _validate() { $method = $this->uri->segment(3, ''); if ( ! in_array($method, $this->data['methods']) ) return FALSE;
/** 驗證資料 */ $this->load->config('finance', true); $this->load->library("payment/{$method}", NULL, 'Payment'); return $this->Payment->respond(); }}
/* End of file payment.php *//* Location: ./application/controllers/payment.php */