PHP/THINKPHP创建优惠券码

来源:互联网 发布:java环境变量设置脚本 编辑:程序博客网 时间:2024/05/02 02:41
<?phpnamespace Addons\Coupon\Controller;use Home\Controller\AddonsController;class WapController extends AddonsController{    protected $model;    public function __construct() {        $GLOBALS ['is_wap'] = true;        parent::__construct ();        $uid= get_uid_by_openid();        $this->model = getModelByName ('coupon');        $this->model || $this->error ( 'model is not found!' );    }    /*     * Create coupon code     *      * @param  $namespace string     * @return $guid string      * @author sun     */    private function create_guid($namespace = '') {        static $guid = '';        $uid = uniqid("", true);        $data = $namespace;        $data .= $_SERVER['REQUEST_TIME'];        $data .= $_SERVER['HTTP_USER_AGENT'];        $data .= $_SERVER['LOCAL_ADDR'];        $data .= $_SERVER['LOCAL_PORT'];        $data .= $_SERVER['REMOTE_ADDR'];        $data .= $_SERVER['REMOTE_PORT'];        $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));        // test str combination        $guid =        substr($hash, 0, 6) .        '-' .        substr($hash, 8, 4) .        '-' .        substr($hash, 12, 4) .        '-' .        substr($hash, 16, 4) .        '-' .        substr($hash, 20, 8);        return $guid;    }}// end
0 0
原创粉丝点击