12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- require_once 'api.php';
- $trade_order_id = time();
- $appid = '201906120002';
- $appsecret = '7a0967a8f830c9319c87e01e691b8f09';
- $my_plugin_id ='my-plugins-id';
- $data=array(
- 'version' => '1.1',
- 'lang' => 'zh-cn',
- 'plugins' => $my_plugin_id,
- 'appid' => $appid,
- 'trade_order_id'=> $trade_order_id,
- 'payment' => 'wechat',
- 'type' => 'WAP',
- 'wap_url' => home_url(),
- 'wap_name' => home_url(),
- 'total_fee' => '0.1',
- 'title' => '耐克球鞋',
- 'time' => time(),
- 'notify_url'=> 'http://www.xx.com/notify.php',
- 'return_url'=> 'http://www.xx.com/pay/success.html',
- 'callback_url'=>'http://www.xx.com/pay/checkout.html',
- 'modal'=>null,
- 'nonce_str' => str_shuffle(time())
- );
- $hashkey =$appsecret;
- $data['hash'] = XH_Payment_Api::generate_xh_hash($data,$hashkey);
- $url = 'https://api.xunhupay.com/payment/do.html';
- try {
- $response = XH_Payment_Api::http_post($url, json_encode($data));
-
- $result = $response?json_decode($response,true):null;
- if(!$result){
- throw new Exception('Internal server error',500);
- }
- $hash = XH_Payment_Api::generate_xh_hash($result,$hashkey);
- if(!isset( $result['hash'])|| $hash!=$result['hash']){
- throw new Exception(__('Invalid sign!',XH_Wechat_Payment),40029);
- }
- if($result['errcode']!=0){
- throw new Exception($result['errmsg'],$result['errcode']);
- }
- $pay_url =$result['url'];
- header("Location: $pay_url");
- exit;
- } catch (Exception $e) {
- echo "errcode:{$e->getCode()},errmsg:{$e->getMessage()}";
-
- }
- ?>
|