Пример #1
0
include_once "lib/WxpayClientPub.php";
include_once "lib/UnifiedOrderPub.php";
error_reporting(E_ALL);
// 获取微信用户的openId,相信在接微信支付的时候,已经能够获取到openId了
//$openId = "oczZouEKDQvL-tX1VIfN3-FK9RDw";
$appId = WxPayConfig::APPID;
$appSecret = WxPayConfig::APPSECRET;
// 获取jssdk相关参数
$jssdk = new JsSdk($appId, $appSecret);
$signPackage = $jssdk->GetSignPackage();
$timeStamp = $signPackage['timestamp'];
$nonceStr = $signPackage['nonceStr'];
$out_trade_no = $appId . $timeStamp;
// 获取prepay_id
// 具体参数设置可以看文档http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1
$unifiedOrder = new UnifiedOrderPub();
//$unifiedOrder->setParameter("openid",$openId);//用户openId
$unifiedOrder->setParameter("body", "贡献一分钱");
//商品描述,文档里写着不能超过32个字符,否则会报错,经过实际测试,临界点大概在128左右,稳妥点最好按照文档,不要超过32个字符
$unifiedOrder->setParameter("out_trade_no", $out_trade_no);
//商户订单号
$unifiedOrder->setParameter("total_fee", "1");
//总金额,单位为分
$unifiedOrder->setParameter("notify_url", WxPayConfig::NOTIFY_URL);
//通知地址
$unifiedOrder->setParameter("trade_type", "APP");
//交易类型
$unifiedOrder->setParameter("nonce_str", $nonceStr);
//随机字符串
//非必填参数,商户可根据实际情况选填
//$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号
Пример #2
0
include_once "lib/CommonUtilPub.php";
include_once "lib/SDKRuntimeException.php";
include_once "lib/WxpayClientPub.php";
include_once "lib/UnifiedOrderPub.php";
// 获取微信用户的openId,相信在接微信支付的时候,已经能够获取到openId了
$openId = "o5k3_xxxxxxxxxxxxxxxxxx";
$appId = WxPayConfPub::APPID;
$appSecret = WxPayConfPub::APPSECRET;
// 获取jssdk相关参数
$jssdk = new JsSdk($appId, $appSecret);
$signPackage = $jssdk->GetSignPackage();
$timeStamp = $signPackage['timestamp'];
$nonceStr = $signPackage['nonceStr'];
// 获取prepay_id
// 具体参数设置可以看文档http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1
$unifiedOrder = new UnifiedOrderPub();
$unifiedOrder->setParameter("openid", $openId);
//用户openId
$unifiedOrder->setParameter("body", "贡献一分钱");
//商品描述,文档里写着不能超过32个字符,否则会报错,经过实际测试,临界点大概在128左右,稳妥点最好按照文档,不要超过32个字符
$unifiedOrder->setParameter("out_trade_no", "123456");
//商户订单号
$unifiedOrder->setParameter("total_fee", "1");
//总金额,单位为分
$unifiedOrder->setParameter("notify_url", WxPayConfPub::NOTIFY_URL);
//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");
//交易类型
$unifiedOrder->setParameter("nonce_str", $nonceStr);
//随机字符串
//非必填参数,商户可根据实际情况选填