Tencent app task Market signed PHP implementation code

Source: Internet
Author: User

1<?PHP2 3 $appKey= "Xxxxxxxxxxx";//secret key4 $paths= ' get&%2fjob.php& ';//IfThe callback file is under the root directory/job.php5 $result=$_get;6 Ksort($result);//Sort7 $step=$_get[' Step '];//The first few steps8 $str= "";9 Ten $MD 5pkey=$_get[' Pkey '];//Pkey One $MD 5Str=MD5($_get[' OpenID '].$appKey.$_get[' ts ']);//Verifying Pkey signatures A  - foreach($result  as $key=$val){ -     if($key! = "SIG"){ the       $array _str=Str_split($val); -       foreach($array _str  as $key 2=$val 2){ -         if(!Ereg("^ ([a-za-z0-9!* ()])",$val 2)){ -           $array _str[$key 2] = "%".Strtoupper(Bin2Hex($val 2)); +         } -        } +       $val=implode(‘‘,$array _str); A       if($str== ""){ at         $str=$key." =".$val; -}Else{ -           $str=$str." & ".$key." =".$val; -       } -     } - } in $str=UrlEncode($str); - $sig 2=Base64_encode(Custom_hmac (' SHA1 ',$paths.$str,$appKey)); to  +  - if($sig 2==$_get[' Sig '] &&$MD 5Str==$MD 5pkey){ the //Validation by *      if($step= = 1){ $         //Working with CodePanax Notoginseng         $data=Array("ret" =>0, "msg" = "OK", "zoneid" = "1"); -         EchoMjson ($data); the}ElseIf($step= = 2){ +         //Working with Code A         $data=Array("ret" =>0, "msg" = "OK2", "ZoneID" = "1"); the         EchoMjson ($data); +}ElseIf($step= = 3){ -         //Working with Code $         $data=Array("ret" =>0, "msg" = "OK3", "ZoneID" = "1"); $         EchoMjson ($data); -       } -}Else{ the         //validation does not pass -         $data=Array("ret" =>200, "msg" = = ' parameter error ', "ZoneID" = "1");Wuyi         EchoMjson ($data); the } -  Wu functionMjson ($data) - { About     if(!headers_sent())Header("Content-type:application/json; Charset=utf-8 "); $     EchoJson_encode ($data); - }  - functionCustom_hmac ($algo,$data,$key,$raw _output=true) - { A     $key=$key." & "; +     $algo=Strtolower($algo); the     $pack= ' H '.strlen($algo(' Test ')); -     $size= 64; $     $opad=str_repeat(CHR(0x5C),$size); the     $ipad=str_repeat(CHR(0x36),$size); the  the     if(strlen($key) >$size) { the         $key=Str_pad(Pack($pack,$algo($key)),$size,CHR(0x00)); -}Else { in         $key=Str_pad($key,$size,CHR(0x00)); the     } the  About      for($i= 0;$i<strlen($key)-1;$i++) { the         $opad[$i] =$opad[$i] ^$key[$i]; the         $ipad[$i] =$ipad[$i] ^$key[$i]; the     } +  -     $output=$algo($opad.Pack($pack,$algo($ipad.$data))); the Bayi     return($raw _output) ?Pack($pack,$output) :$output; the }  the?>

Related Article

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.