示例#1
0
 /**
  * 设置商户
  */
 public function setBusiness(Business $business)
 {
     if (null !== $business) {
         try {
             $business->checkParams();
         } catch (Exception $e) {
             throw new PaymentException($e->getMessage());
         }
         $this->business = $business;
     }
 }
示例#2
0
if (!isset($_SESSION['openid'])) {
    $o = new OAuth(APPID, APPSECRET);
    if (!isset($_GET['code'])) {
        $o->authorize(Util::currentUrl());
    } else {
        $token = $o->getAccessToken($_GET['code']);
        $_SESSION['openid'] = $token->openid;
    }
}
/**
 * 第 1 步:定义商户
 * 设置商户证书路径请使用 setClientCert/setClientKey
 * $business->setClientCert('/your/path/to/apiclient_cert.pem');
 * $business->setClientKey('/your/path/to/apiclient_key.pem');
 */
$business = new Business();
$business->appid(APPID);
$business->appsecret(APPSECRET);
$business->mch_id(MCHID);
$business->mch_key(MCHKEY);
// print_r($business->getParams());
/**
 * 第 2 步:定义订单
 */
$order = new Order();
$order->body('iphone 6 plus');
$order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999));
$order->total_fee('1');
// $order->openid($_SESSION['openid']);
$order->openid('oWY-5jjLjo7pYUK86JPpwvcnF2Js');
$order->notify_url('http://code.1999.me/Wechat/example/payment_notify.php');
示例#3
0
 * 微信服务器请求过来的数据
 */
$request = Util::XML2Array($request);
// $request = array(
//     "appid" => "wx345f3830c28971f4",
//     "openid" => "oWY-5jjLjo7pYUK86JPpwvcnF2Js",
//     "mch_id" => "1241642202",
//     "is_subscribe" => "Y",
//     "nonce_str" => "fhKb6Fkzm3UJrX95",
//     "product_id" => "2015080618052364076",
//     "sign" => "1ED0F1A052F5212009E7C5DB89C57789"
// );
/**
 * 统一下单
 */
$business = new Business();
$business->appid(APPID);
$business->appsecret(APPSECRET);
$business->mch_id(MCHID);
$business->mch_key(MCHKEY);
$order = new Order();
$order->body('iphone 6 plus');
$order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999));
$order->total_fee('1');
$order->openid($request['openid']);
$order->notify_url('Your notify url');
$unifiedorder = new Unifiedorder($business, $order);
$response = $unifiedorder->getResponse();
/**
 * 响应订单
 */