Skip to content

H5纯签约

该方式适用于手机、平板电脑等使用H5浏览器的设备场景使用微信签约扣款。商户在网站前端通过微信支付H5纯签约接口与用户签订委托扣款协议,再通过后台接口申请扣款来完成代扣交易。

🔐

  • 如果签约成功,微信会异步通知给商户(notify_url为通知路径),如果签约失败则不通知。
  • 调用此接口后获得redirect_url,需要在前端跳转到redirect_url,在商户的前端页面<head>处需要添加声明<meta name="referrer" content="no-referrer-when-downgrade">
  • 此外,不能使用window.location.replace(redirect_url)的方式跳转,而要通过window.location.href = redirect_url的方式跳转。
  • redirect_url页面,会唤起微信。无论用户是否同意,redirect_url的页面会在3秒后自动回到refer页面。
  • 如果获取的refer只有域名没有路径,那么签约完成后,需要用户手动回到浏览器。
  • 特别提醒:H5纯签约接口暂未对外开放,如有需要请咨询对接的业务人员,额外申请开通。
请求参数类型描述
noncelesstrue声明请求的query无随机字符串参数
queryobject声明请求的查询参数
appidstring应用ID
mch_idstring商户号
plan_idstring模板id
contract_codestring签约协议号
request_serialinteger请求序列号
contract_display_accountstring用户账户展示名称
notify_urlstring回调通知url
versionstring版本号
1.0 枚举值
signstring签名
sign_typestring签名类型
MD5 | HMAC-SHA256 枚举值之一
timestampstring时间戳
return_appidstring回调应用appid
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$instance->v2->papay->h5entrustweb->getAsync([
  'nonceless' => true,
  'query' => $params
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$instance->chain('v2/papay/h5entrustweb')->getAsync([
  'nonceless' => true,
  'query' => $params
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$instance['v2/papay/h5entrustweb']->getAsync([
  'nonceless' => true,
  'query' => $params
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$response = $instance->v2->papay->h5entrustweb->get([
  'nonceless' => true,
  'query' => $params
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$response = $instance->chain('v2/papay/h5entrustweb')->get([
  'nonceless' => true,
  'query' => $params
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
php
use WeChatPay\Crypto\Hash;
use WeChatPay\Formatter;

$params = [
  'appid'                    => 'wxcbda96de0b165486',
  'mch_id'                   => '1200009811',
  'plan_id'                  => '12535',
  'contract_code'            => '100000',
  'request_serial'           => '1000',
  'contract_display_account' => '微信代扣',
  'notify_url'               => 'https://weixin.qq.com',
  'version'                  => '1.0',
  'sign_type'                => 'HMAC-SHA256',
  'timestamp'                => Formatter::timestamp(),
  'clientip'                 => '119.145.83.6',
  'deviceid'                 => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'mobile'                   => '18933432355',
  'email'                    => 'aobama@whitehouse.com',
  'qq'                       => '100243',
  'openid'                   => 'baf04e6bbbd06f7b1a197d18ed53b7f1',
  'creid'                    => '110102199701011000',
  'outerid'                  => 'user123',
  'return_appid'             => 'wxcbda96de0b165486',
];
$params['sign'] = Hash::sign(
  Hash::ALGO_HMAC_SHA256,
  Formatter::queryStringLike(
    Formatter::ksort($params)
  ),
  $apiv2Key
);

$response = $instance['v2/papay/h5entrustweb']->get([
  'nonceless' => true,
  'query' => $params
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
返回字典类型描述
return_codestring返回状态码
SUCCESS | FAIL 枚举值之一
return_msgstring返回信息
result_codestring业务结果
SUCCESS | FAIL 枚举值之一
result_msgstring业务结果描述
redirect_urlstring跳转URL,有效期为10分钟

参阅 官方文档 官方文档

Published on the GitHub by TheNorthMemory