PHP to do RSA signature generation order

Source: Internet
Author: User
Tags array sort urlencode

Combination signature $a=time (); $b =substr ($a,  1);//Generate random order number $orderid=  $b. Mt_rand (10000,99999);//co-Identity ID, 16-bit pure number starting with 2088 $mygoods [' partner ']= "2088011744308664";//Merchant account $mygoods[' seller ']= "[email protected]";//Order number $mygoods[' Out_ Trade_no ']= $orderid;//Theme $mygoods[' subject ']= $goods _name;//Product description Information $mygoods[' body ']= $goods _infro;//commodity price $mygoods[' Total_fee ']= $score;//server-side asynchronous response Address $mygoods[' Notify_url ']=  "http://211.149.220.47/php/notify_url.php";//Sort $ Mygoods = argsort ($mygoods);//Stitching $mystr = createlinkstring ($mygoods);//Signature $sign =  Rsasign ($MYSTR);//UrlEncode transcoding $sign = urlencode ($sign) for signatures,//Generate final signature information $orderinfor =  $mystr. " &sign= ". $sign." &sign_type=rsa ";/** *  all elements of the array, using" & "characters in the pattern of" parameter = parameter value "to string  *  @param   $para   Need to splice the array  * return  stitch complete After the string  */function createlinkstring ($para)  {$arg    =  "";while  (list  ($key,  $val)  = each  ($para)  {$arg. = $key. " = ". $vaL. " & ";} Remove the last & character $arg = substr ($arg, 0,count ($arg)-2);//If an escape character exists, then remove the escape if (GET_MAGIC_QUOTES_GPC ()) {$arg  = stripslashes ($arg);} return  $arg;} /** *  array sort  *  @param   $para   sort before sorting  * return  sorted array  */function  argsort ($para)  {ksort ($para); reset ($para);return  $para;} /** * rsa Signature  *  @param   $data   data to be signed  *  @param   $private _key_path  Merchant private key file path  * return  signature result  */function rsasign ($data,  $private _key_path)  {      $priKey  = file_get_contents ($private _key_path);     $res  =  openssl_get_privatekey ($priKey);     openssl_sign ($data,  $sign,  $res);     openssl_free_key ($res);//base64 Code      $sign  = base64_ Encode ($sign);    return  $sign;}


PHP to do RSA signature generation order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.