Today's headlines on issues related to small programs (applets beating bytes)

Last week, suddenly encountered lets developers Today's headlines applet (byte beating applet) needs and then looked at the document found is really simple. And the document typos. A bit more slot points. But small and old versions of the program are very similar, and then I try holding the mentality, to really try small micro-channel program changed the id, and then upload the package, I discovered running through! Run through! Run through! Once again run through. At that time my heart collapse, saying good tt. That label, so really you copy, at any rate slightly change the next ah.

Let me talk about a few reasons arraigned next encounter does not pass:

  1, in the part of the page has a micro-channel micro-channel or two-dimensional code sharing and other micro-channel and related things (because it is a small program directly to the micro-letter threw all know a little trouble)

  2, requested page can not have a blank, not the least thing to have text prompts, I did not expect this be the beginning of the user experience

  3, video requires the ability to drop down automatically when the page Skip suspended or floating window display (because the document is not detailed, very little information on the Internet, there is no information on the community, especially Tucao, community officials to respond to the speed of slow, basically throwing documents link or example, feeling very friendly to developers, particularly in the document is not too clear question)

Pit encountered, mainly in the payments side, other problem areas can refer to small micro-channel program, General basic document. Headline I did not have to pay channels, so using Alipay, usett.requestPayment()调起支付宝APP支付:

Pay specific procedures: the back-end to generate a headline order number by openid and their side order number, the specific operation can be seen document flow, and then generates a call to a string Alipay, where the need to use Alipay document, Alipay SDK I used many, very good document here Alipay, the online information. The final step is to call the assembly to return to the front-end Alipay. Of particular note is that all appid and other parameters used here are the headlines assigned to appid merchants and so on.

  1, signed the official document, pay access the document, there is a signature notes and signatures do not by description, there is a pit that is the signature description is that under a single signature, the signature is not by way of illustration and example is a front-end call Alipay APP signature.

  My code here for the convenience of display, with stitching:

$biz_content = array(

            'out_order_no' => $ordersn,

            'uid' => $openid,

            'merchant_id' => $ttshcode[$appid],

            'total_amount' =>$order['orderAmount'] ? $order['orderAmount'] * 100 : 0,

            'currency' => 'CNY',

            'subject' => $order['goodsName'] ? $order['goodsName'] :'名称' ,

            'body' => $ordersn.','.$order['orderAmount'],

            'trade_time' => $time,

            'valid_time' => '60',

            'notify_url' => 'http://www.******.com',

            'risk_info' => '127.0.0.1',

        );


        $biz_content = json_encode($biz_content);

        $data['app_id'] = $ttapppay[$appid];

        $data['biz_content'] = $biz_content;

        $data['charset'] = 'utf-8';

        $data['method'] = 'tp.trade.create';

        $data['sign_type'] = 'MD5';

        $data['timestamp'] = $time;

        $data['version'] = '1.0';

        ksort( $ Data ); 

        $ var = '' ; 

        foreach ( $ data  as  $ key => $ value ) { 

            $ was . = $ key . '='. $ value . '&' ; 

        } 
        $ Was = trim ( $ were , '&' ); 


        $ c = $ var . $ secret ; 

        $ data [ 'sign'] = MD5 ( $ c );
  
        ksort ( $ data ); 

        $ vars = '' ;
        $ vars = 'app_id ='.$data['app_id'].'&biz_content='.$data['biz_content'].'&charset='.$data['charset'].'&method='.$data['method'].'&sign='.$data['sign'].'&sign_type='.$data['sign_type'].'&timestamp='.$data['timestamp'].'&version='.$data['version'];
        $url = 'https://tp-pay.snssdk.com/gateway';
     //进行post请求

2. Alipay here to pay Alipay string reference document generation

3. The front-end call Alipay app, here is an example there is a pit in the treasure to pay out a string braces, here are tips on signature error,

Code Example:

     $ goodsName = $ the Order ? [ 'goodsName'] $ the Order [ 'goodsName']: 'name' ;
         $ urls = $ the this -> alipay_get ( $ goodsName , $ DATAS [ 'the Response'] [ 'trade_no'], $ the Order [ 'orderAmount' ]); // here is what I wrote a method call Alipay SDK signature function 

        $ List [ 'app_id'] = $ ttapppay [ $ AppID ]; // the Test 
        $ List [ 'method,'] = 'TP .trade.confirm ' ;
         $ List [' sign_type '] = the MD5 ;
         $ List [ "UID"] = $ OpenID ;
        $list["total_amount"]=$order['orderAmount'] ? $order['orderAmount']*100 : 0;
        $list['timestamp'] = time();
        $list['pay_channel'] = "ALIPAY_NO_SIGN";
        $list["pay_type"] = "ALIPAY_APP";
        $list["trade_no"]= $datas['response']['trade_no'];
        $list["merchant_id"]= $ttshcode[$appid];
        $list["risk_info"]= $this->input->ip_address();
        $list["uid"]=$openid;
        $arrParam=array("url" =>  $urls);
        $strParam=json_encode($arrParam);
        $list["params"]=$strParam;
        $list['url'] =$urls;
        $signKeys=array("app_id","sign_type","timestamp","trade_no","merchant_id","uid","total_amount","params");
        $signData=array();
        ] =$ v[$ signData) {
            $ vas with the$ signKeys(the foreach  $list[$v];
        }

        ksort($signData);
        $var = '';
        foreach($signData as $key => $value){
            $var .= $key.'='.$value.'&';
        }
        $var = trim($var,'&');
        $list['sign'] = MD5($var . $secret);
$ datas [ 'response'] [ 'trade_no'] is a single number generated. 
4. The front-end code:
var obj = JSON.parse(res.data.data);//

                tt.requestPayment({
                    data: {
                        app_id: obj.app_id,
                        method: 'tp.trade.confirm',
                        sign: obj.sign,
                        sign_type: 'MD5',
                        timestamp: obj.timestamp.toString(),
                        trade_no: obj.trade_no,
                        merchant_id: obj.merchant_id,
                        uid: obj.uid,
                        total_amount: obj.total_amount,
                        pay_channel: 'ALIPAY_NO_SIGN',
                        pay_type: 'ALIPAY_APP',
                        risk_info: "{'ip':'"+obj.risk_info+"'}",
                        params: JSON.stringify({
                                url:obj.url
                           }),
                        return_url: 'https://***********/',
                        show_url: 'https://*********/',
                    },
                    success (res) {
                        succ(res);
                        console.log(res);
                    },
                    fail (res) {
                        console.log(res);
                        wx.showModal({
                            title: '支付失败',
                            content: '',
                            complete (res) {
                                return tt.navigateTo({
                                    url: '/pages/user/orders/orders'
                                });
                            }
                        });
                        fail(res);
                    }
                })

My side is returned by the backend json format, front-end into an object.

Guess you like

Origin www.cnblogs.com/zdzdbk/p/10969358.html