Posted on

whmcs微信支付接口(免签约)

whmcs支持2种支付方式:

  1. 第三方网关 – 消费者离开网站支付,支付完成后返回。
  2. 商家网关 – 消费者直接输入cc信息. 支付在后台处理.

首先下载官方的示例接口:https://github.com/WHMCS/sample-gateway-module/
把gatewaymodule.php和callback/gatewaymodule.php改名为weichat.php。打开weichat.php,修改gatewaymodule_为weichat_。删除_refund和_cancelSubscription这2个函数。
设置weichat_config函数,用来在激活网关时在后台设置一些选项。
设置link函数,用来把用户带到支付网关,这个函数输出的是html代码,一般是<form>表单里用一个post方法提交。
修改callback代码,callback用来接收支付网关的返回,并把支付结果通知到whmcs。
那么免签如何实现呢?就是模拟一个支付宝接口,收到支付请求后首先取出事先生成好的二维码,在一个终端设备监控支付工具的收款记录,如果有匹配,通知到服务器,客户端浏览器在接到支付成功的信息后,重定向到callback函数。

-end-

Posted on

whmcs插件开发完全手册

whmcs是一款主机自动销售软件,用php开发,可销售虚拟主机、vps、独立服务器,可以自动收费和开通服务。另外一个用途是可出售虚拟服务,例如ss服务。
whmcs的插件有4种类型:产品和服务插件、系统扩展插件、域名注册插件和支付网关插件。我们主要关注前2个类型。

产品和服务插件:

插件的核心功能是创建, 暂停, 开通, 和终止产品. 这些功能的触发条件是下面的事件:

  • 新订单付款
  • 订单到期
  • 到期付费
  • 取消操作

WHMCS 插件可以实现下面的功能:

  • 自动密码重置
  • 升级和降级
  • 更新
  • 后台链接
  • 客户后台输出
  • 自定函数可以实现更多

文件目录:插件存放在/modules/servers/目录下。

配置选项:

用来设置每一个产品。函数用yourmodulename_ConfigOptions命名。
支持下面的类型:

  • Text
  • Password
  • Yes/No Checkboxes
  • Dropdown Menus
  • Radio Buttons
  • Text Areas

元数据参数:

有以下参数可设置
DisplayName
APIVersion
RequiresServer
DefaultNonSSLPort
DefaultSSLPort
ServiceSingleSignOnLabel
AdminSingleSignOnLabel

支持函数:

这是产品服务插件所有可包含函数的概览。函数是可选的,如果不应用可以不包含。 所有的函数必须有前缀filename_后接函数名. 函数名包含下面的:

CreateAccount

This function runs when a new product provisions. This can be by WHMCS upon checkout or payment for a new order. Also, by an admin user from the Products/Services tab in a clients profile of the admin area.

SuspendAccount

This function runs when a suspension is requested. Requested by the WHMCS Cron when a product becomes overdue, or by admin user in the Client Profile.

UnsuspendAccount

This function runs when an unsuspension is requested. Requested upon payment of an overdue invoice for a product.

TerminateAccount

This function runs when a termination is requested. Requested by the WHMCS Cron for long overdue products when enabled (Automation Settings). Also requested by an admin user in the Client Profile.

Renew

This function runs each time a renewal invoice for a product becomes paid.

ChangePassword

This function runs as a client requests a password change. The option will not show up if the function is not defined in the module. The status of the product must also be active. Admins can also invoke this command from the admin area.

ChangePackage

This function runs for upgrading and downgrading of products. This function runs when an upgrade or downgrade order placed by the client becomes paid. Admins can also invoke this from the product management pages. The same function runs for upgrades and downgrades of both products and configurable options.

ClientArea

This function can be used to define module specific client area output. It accepts a return of HTML for display on the product details page of the client area. Output via a template file within the module folder named “clientarea.tpl” is also possible. Discussion of this function in more detail later on in the docs.

AdminArea

Used to define HTML code that displays on server configuration page (Setup > Products/Services > Servers). Used to provide an automated shortcut/login link to the integrated server control panel.

Used to define HTML code to link to the customers account on a server control panel. Displayed on the product management page of the admin area. The return must be HTML output or link (no forms).

ClientAreaCustomButtonArray

Used to define custom functions that your module supports. Customers can invoke and run these from the client area. The functions can perform actions or product page output in the client area. Example usages for this are to provide product management pages, bandwidth reporting pages, etc…

ClientAreaAllowedFunctions

Like the above, used to define custom functions. Customers can invoke, but are not shown as buttons by default (i.e. custom client area output will invoke them).

AdminCustomButtonArray

Used to define custom functions in your module for admin users. This can contain more functions than the client area equivalent.

UsageUpdate

Used to perform a daily import of the disk and bandwidth usage from a server. The data imported is then used to display the usage stats both within the client and admin areas of WHMCS. The data is also used in disk and bandwidth overage billing calculations if enabled for a product.

AdminServicesTabFields

Used to define extra fields or output to display within admin product pages.

AdminServicesTabFieldsSave

Used in conjunction with the above. This function handles the values submitted in any custom fields when a save occurs.

插件参数:

插件参数是引用时传给每个函数的数据/值。每一个插件函数收到同样的参数. 这些参数提供关于插件命令运行的特定产品/服务的信息。参数也包含了产品自己的设置。
产品服务插件示例代码:https://github.com/WHMCS/sample-provisioning-module

附加插件:

附加插件允许你创建管理员页面和钩子去扩展whmcs功能。
附加插件可以仅包含管理页面, 仅钩子或者都包含。她们都可以通过Setup > Addon Modules界面管理。
一旦激活,插件将显示在附加菜单可以在后台随时访问。
管理选项包含激活和停止插件。 访问控制允许决定哪一个管理角色可以访问插件。

上手:

插件放在/modules/addons/目录下,/your_module_name/ 目录是你的插件目录,核心插件your_module_name.php应该放在此目录下。

配置:

第一步是配置插件,包含插件名, 版本, 作者, 描述。同样也有自定义配置项。

安装和卸载:

插件可以包含激活和停止函数。 这些函数当管理员激活或者停止时运行。
这些函数可以用来运行任何代码当激活或者停止函数时。例如,创建自定义表, 数据库语句,或者授权检查. 也可以用来返回消息或者错误。
当插件运行时已经有了一个数据库连接,所以连接到WHMCS 数据库你不需要再新建连接。

-end-

Posted on

创建自己的wordpress主题模板

wordpress作为一个成功的php开发的cms程序,适用面非常广,除了常见的blog系统,还被用在企业站、新闻站、门户站等许多领域。可以说使用场景由主题模板决定,所以才显得主题特别重要。

1.建立一个最简单的wordpress主题。

主题文件放在wp-content/themes/中 ,每个主题一个文件夹。

每个主题必须包含的2个文件:

1.)style.css

样式表,文件开头写明主题信息,以便在wp后台做出区别。

2.)index.php

默认模板文件,如果其他模板文件缺失,默认以此文件渲染页面。

2.其他模板文件

模板文件是html代码、模板标签和php代码的混合。不同的模板文件影响页面不同地方的布局和设计。

1.)front-page.php

主页文件。不管后台如何设置,如果此文件存在,以此文件为准。

2.)home.php

默认主页文件。如果后台不设置为主页为静态页面,默认用此模板显示。

3.)header.php

包含document type、meta标签、链接到样式表和js文件。

4.)single.php

请求一篇文章时被应用。

5.)single-{post-type}.php

用于自定义文章类型的文章显示。

6.)page.php

用于显示单个页面。

7.)archive.php

当请求按分类、作者和日期显示文章时,应用此模板。当有category.phpauthor.php或者date.php更详细的模板时,覆盖它。

还有一些文件没有介绍。

3.模板层级

层级解释每一个页面在渲染时该应用哪个模板文件。

1.)主页

  1. front-page.php – 不管后台如何设置,只要存在此文件,主页会用此文件渲染。
  2. home.php – 没有找到front-page.php并且设置首页显示最新文章, 会用home.php渲染. 或者某个文章页被设置成了首页,会用此文件渲染。
  3. page.php – 当页面被设置成主页,会用page.php渲染。
  4. index.php – 以上文件都不存在时用此文件渲染。

2.)文章页

  1. single-{post-type}-{slug}.php – (Since 4.4) First, WordPress looks for a template for the specific post. For example, if post type is product and the post slug is dmc-12, WordPress would look for single-product-dmc-12.php.
  2. single-{post-type}.php – If the post type is product, WordPress would look for single-product.php.
  3. single.php – WordPress then falls back to single.php.
  4. singular.php – Then it falls back to singular.php.
  5. index.php – Finally, as mentioned above, WordPress ultimately falls back to index.php.

3.)页面

  1. custom template file – The page template assigned to the page. See get_page_templates().
  2. page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php.
  3. page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php.
  4. page.php
  5. singular.php
  6. index.php

4.)分类

  1. category-{slug}.php – If the category’s slug is news, WordPress will look for category-news.php.
  2. category-{id}.php – If the category’s ID is 6, WordPress will look for category-6.php.
  3. category.php
  4. archive.php
  5. index.php

5.)标签

  1. tag-{slug}.php – If the tag’s slug is sometag, WordPress will look for tag-sometag.php.
  2. tag-{id}.php – If the tag’s ID is 6, WordPress will look for tag-6.php.
  3. tag.php
  4. archive.php
  5. index.php

4.模板标签

模板标签用在主题模板中用于从数据库中取出内容。这些内容可以是任何信息:从博客标题到完整的边栏。
使用模板标签的原因:

  • 动态提取内容;
  • 可以用在多个主题模板中;
  • 把模板分离为更小、更容易理解的片段。

例子:get_header();the_title();bloginfo( ‘name’ );

5.循环

循环是wp默认输出文章的机制。
循环的例子:

<?php
    get_header();
    if ( have_posts() ) : while ( have_posts() ) : the_post();
        the_content();
    endwhile;
    else :
        _e( 'Sorry, no posts matched your criteria.', 'textdomain' );
    endif;
    get_sidebar();
    get_footer();
?>
循环中可以显示的标签:
  • next_post_link() – a link to the post published chronologically after the current post
  • previous_post_link() – a link to the post published chronologically before the current post
  • the_category() – the category or categories associated with the post or page being viewed
  • the_author() – the author of the post or page
  • the_content() – the main content for a post or page
  • the_excerpt() – the first 55 words of a post’s main content followed by an ellipsis (…) or read more link that goes to the full post. You may also use the “Excerpt” field of a post to customize the length of a particular excerpt.
  • the_ID() – the ID for the post or page
  • the_meta() – the custom fields associated with the post or page
  • the_shortlink() – a link to the page or post using the url of the site and the ID of the post or page
  • the_tags() – the tag or tags associated with the post
  • the_title() – the title of the post or page
  • the_time() – the time or date for the post or page. This can be customized using standard php date function formatting.

条件标签:

  • is_home() – Returns true if the current page is the homepage
  • is_admin() – Returns true if inside Administration Screen, false otherwise
  • is_single() – Returns true if the page is currently displaying a single post
  • is_page() – Returns true if the page is currently displaying a single page
  • is_page_template() – Can be used to determine if a page is using a specific template, for example: is_page_template('about-page.php')
  • is_category() – Returns true if page or post has the specified category, for example: is_category('news')
  • is_tag() – Returns true if a page or post has the specified tag
  • is_author() – Returns true if inside author’s archive page
  • is_search() – Returns true if the current page is a search results page
  • is_404() – Returns true if the current page does not exist
  • has_excerpt() – Returns true if the post or page has an excerpt

-end-