yuchao 发表于 2018-2-11 12:03:58


            本文实例讲述了php版微信js-sdk支付接口类用法。分享给大家供大家参考,具体如下:
这个支付类是根据官方的文档修改而来!主要实现生成JS API 、Native的package签名包和Native响应的XML格式数据。注释都标上了各方法的用意。由于package包签名,略复杂,这个要自己多花时间去对应去看和log出文件来一一对比!当然只要你用上教程的类,设置好对应的参数就可以正确的生成package参数等
= 1 && $argv == __FILE__) {
//初始化pay的必要信息
$pay = new WechatPay(array(
    WechatPay::APPID => 'wx99dabzpiuq83985b8',
    WechatPay::APPSERCER => 'ac12e7e4abaer63hkoa0cc36a9663fa',
    WechatPay::PARTNERKEY => 'bae4sfa3562rsfaq23s2045',
    WechatPay::PARTNERID => '1268969802',
    WechatPay::PAYSIGNKEY => '9Fqsxb3PK4IVOCEc4yCquy5zecS9LeeMjF2Nn4B4YKoOxPwaQdFwMezKT8oNlBYaWcuT',
    WechatPay::SIGNTYPE => 'sha1',
));
//设置package 必要的参数 jsapi native都通用
$pay->setParams(WechatPay::BANK_TYPE, "WX");
$pay->setParams(WechatPay::BODY, "test");
$pay->setParams(WechatPay::PARTNER, $pay->partnerid);
$pay->setParams(WechatPay::OUT_TRADE_NO, commonUtil::createNoncestr());
$pay->setParams(WechatPay::TOTAL_FEE, "1");
$pay->setParams(WechatPay::FEE_TYPE, "1");
$pay->setParams(WechatPay::TIMESTAMP, time());
$pay->setParams(WechatPay::NOTIFY_URL, "http://www.demo.com/notify");
$pay->setParams(WechatPay::SPBILL_CREATE_IP, "127.0.0.1");
$pay->setParams(WechatPay::INPUT_CHARSET, "UTF-8");
//JSAPI的签名json
print_r($pay->createJsApiPackage());
//生成native XML
print_r($pay->createNativePackage());
//生成native URL
print_r($pay->createNativeUrl("9701"));
}
页: [1]
查看完整版本: php版微信js-sdk支付接口类用法示例